diff --git a/library_scipy.ipynb b/library_scipy.ipynb index ea8a056..6746bbf 100644 --- a/library_scipy.ipynb +++ b/library_scipy.ipynb @@ -1687,8 +1687,12 @@ "metadata": {}, "outputs": [], "source": [ + "import numpy as np\n", + "\n", "xdata = [ -10.0, -9.0, -8.0, -7.0, -6.0, -5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]\n", - "ydata = [1.2, 4.2, 6.7, 8.3, 10.6, 11.7, 13.5, 14.5, 15.7, 16.1, 16.6, 16.0, 15.4, 14.4, 14.2, 12.7, 10.3, 8.6, 6.1, 3.9, 2.1]" + "ydata = [1.2, 4.2, 6.7, 8.3, 10.6, 11.7, 13.5, 14.5, 15.7, 16.1, 16.6, 16.0, 15.4, 14.4, 14.2, 12.7, 10.3, 8.6, 6.1, 3.9, 2.1]\n", + "xdata = np.array(xdata)\n", + "ydata = np.array(ydata)" ] }, { @@ -1726,8 +1730,18 @@ "def solution_gaussian(): # do not change the function signature\n", " # 2. TODO: define function to fit: the Gaussian.\n", "\n", - " # 3. TODO: call the curve_fit function here and return the parameters and covariance matrix AS A TUPLE\n", - " pass" + " def gaussian_func(x, a, b):\n", + " \"\"\"\n", + " Use this function signature, and these parameters A and B.\n", + " a: coefficient of the Gaussian\n", + " b: coefficient of the x^2 term\n", + "\n", + " Will probably return an error if you change this.\n", + "\n", + " Returns: the Gaussian function using the parameters a and b\n", + " \"\"\"\n", + " \n", + " # 3. TODO: call the curve_fit function here and return the parameters and covariance matrix AS A TUPLE" ] }, { diff --git a/tutorial/tests/test_library_scipy.py b/tutorial/tests/test_library_scipy.py index 17cf2ce..cf16784 100644 --- a/tutorial/tests/test_library_scipy.py +++ b/tutorial/tests/test_library_scipy.py @@ -118,10 +118,12 @@ def reference_gaussian(): 3.9, 2.1, ] + xdata = np.array(xdata) + ydata = np.array(ydata) # 2. TODO: define the gaussian function here: - def ref_gaussian_math(x, sigma, mu): - return 1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-0.5 * ((x - mu) / sigma) ** 2) + def ref_gaussian_math(x, a, b): + return a * np.exp(-b * x**2) # 3. TODO: call the curve_fit function here: parameters, covariance = curve_fit(ref_gaussian_math, xdata, ydata)