Skip to content

Commit

Permalink
Scipy notebook: fixed the bug in the Gaussian exercise (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramador09 authored Dec 14, 2023
1 parent a711d9b commit 9189d3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 17 additions & 3 deletions library_scipy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -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"
]
},
{
Expand Down
6 changes: 4 additions & 2 deletions tutorial/tests/test_library_scipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9189d3c

Please sign in to comment.