{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Function Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from smpl import plot\n", "import numpy as np\n", "import smpl\n", "import math\n", "smpl.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## without uncertainties" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### $\\dot x = 1- \\exp(- x^2)$\n", "\n", "Fixed point $x = 0$ and \n", "\n", "$\\ddot x = -2x \\exp(-x^2) \\implies \\ddot x(x = 0)=0$\n", "\n", "only metastable for $x\\lt0$\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.function( lambda x : 1- np.exp(-x**2), xaxis=\"$x$\", yaxis=\"$\\\\dot x$\",xmin=-10, xmax=10 )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### $\\dot x = \\ln x$\n", "\n", "Fixed point $x = 1$\n", "\n", "$$\\ddot x = \\frac{1}{x} \\implies \\ddot x(x=1) = 1 > 0$$\n", "\n", "$\\implies$ unstable" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.function( lambda x : np.log(x), xaxis=\"$x$\", yaxis=\"$\\\\dot x$\",xmin=0.1, xmax=5 )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### $\\dot x = -\\tan x$\n", "Fixed points for $x=0$ or $x=\\pm n\\pi$ with $n\\in \\mathbb{N}$\n", "\n", "$$\\ddot x = -\\frac{1}{\\cos^2(x)}$$\n", "\n", "\n", "$$\\ddot x(x=0) = -1 \\lt 0$$\n", "\n", "$$\\ddot x(x=n \\pi) = -1 \\lt 0$$\n", "\n", "$\\implies$ stable" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.function( lambda x : -np.tan(x), xaxis=\"$x$\", yaxis=\"$\\\\dot x$\",xmin=0.1, xmax=5,steps=100 )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## with uncertainties" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import uncertainties as unc\n", "a = unc.ufloat(1,0.1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.function(lambda x : 1- a*np.exp(-x**2), xaxis=\"$x$\", yaxis=\"$\\\\dot x$\",xmin=-1, xmax=1,sigmas=1 )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Complex" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from smpl.stat import fft\n", "y = np.sin(np.arange(256))\n", "print(len(fft(y)))\n", "plot.data(*fft(y),label=\"FFT\",fmt=\"-\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from smpl.stat import fft\n", "plot.data(*fft(np.sin(np.arange(256))),*fft(np.sin(1/np.pi*np.arange(100))),label=\"FFT\",fmt=\"-\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## without xmin and xmax\n", "xmin and xmax will have to be guessed" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from smpl import plot\n", "plot.function(lambda x: x**2,)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from smpl import plot\n", "import numpy as np\n", "def f(x):\n", " return np.exp(x)\n", "plot.function(f,label=\"exp\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from smpl import plot\n", "from smpl import functions as f\n", "def gauss(x):\n", " \"\"\"Gauss\"\"\"\n", " return f.gauss(x,0,1,3,0)\n", "plot.function(gauss)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def gauss(x):\n", " return np.arctan(x)\n", "plot.function(gauss)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def gauss(x):\n", " return np.tan(x)\n", "plot.function(gauss)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def gauss(x):\n", " return np.log(x)\n", "plot.function(gauss)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def gauss(x):\n", " return x**3+5*x**2-2\n", "plot.function(gauss)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def gauss(x):\n", " return x**0.5\n", "plot.function(gauss)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Guessing the interesting regions of a function can't always be correct/satisfactory, especially in numerical unstable regions:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "c=299792458#m/s\n", "h=4.13566769692*10**-15#eVs\n", "kb=8.617333262*10**-5#eV/K\n", "T=273\n", "def Strahlungsgesetz(x):\n", " return 8*np.pi/c**3*h*x**3/(np.exp((h*x)/(kb*T))-1)\n", "plot.function(Strahlungsgesetz,xaxis=\"$x$\", yaxis=\"$\\\\dot x$\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.function(Strahlungsgesetz,xaxis=\"$x$\", yaxis=\"$\\\\dot x$\",xmin=1e-7-2e-2,xmax=1e-7+2e-2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.function(Strahlungsgesetz,xaxis=\"$x$\", yaxis=\"$\\\\dot x$\",xmin=1,xmax=0.3e15)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.15" } }, "nbformat": 4, "nbformat_minor": 4 }