{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Custom fit function" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from smpl import plot\n", "from smpl import io\n", "from smpl import functions as f\n", "import uncertainties.unumpy as unp\n", "import smpl\n", "smpl.__version__" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = data_malus = np.loadtxt(io.find_file(\"test_custom_data.csv\",3),skiprows = 1, delimiter=',')\n", "ydata = unp.uarray(data[:,0],data[:,1])\n", "xdata = unp.uarray(data[:,2],data[:,3])\n", "plot.data(xdata,ydata)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Initial guess\n", "params allows to set initial guess values for fitting." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "def Malus(x,I_max,I_min,w,p):\n", " ''' $(I_{max}-I_{min})*\\\\cos(w*x-p)^2+I_{min} $'''\n", " return (I_max-I_min)*unp.cos(w*x-p)**2+I_min\n", "\n", "plot.fit((xdata),ydata,Malus,xaxis=\"anlge in °\", yaxis=\"intensity in a.u.\", params=[4.6,0.11,0.0175,180+90-137], units=[\"a.u.\",\"a.u.\",\"rad$^{-1}$\",\"rad\"])" ] }, { "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 }