In [70]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import scipy.optimize as opt
For this problem you are given a raw dataset in the file decay_osc.npz. This file contains three arrays:
tdata: an array of time valuesydata: an array of y valuesdy: the absolute uncertainties (standard deviations) in yYour job is to fit the following model to this data:
$$ y(t) = A e^{-\lambda t} \cos{\omega t + \delta} $$First, import the data using NumPy and make an appropriately styled error bar plot of the raw data.
In [72]:
data = np.load('decay_osc.npz')
tdata = data['tdata']
ydata = data['ydata']
dy = data['dy']
In [73]:
plt.errorbar(tdata, ydata, dy,
fmt='.k', ecolor='lightgray')
Out[73]:
In [ ]:
assert True # leave this to grade the data import and raw data plot
Now, using curve_fit to fit this model and determine the estimates and uncertainties for the parameters:
curve_fit to get a good fit.absolute_sigma=True.
In [101]:
def exp_model(t,A,Lambda,Omega,Sigma,):
y = A*np.exp(Lambda*t)*np.cos(Omega*t)
return y
popt, popy = opt.curve_fit(exp_model,tdata,ydata,absolute_sigma=True)
print (popt)
print ()
print (popy)
In [ ]:
assert True # leave this cell for grading the fit; should include a plot and printout of the parameters+errors