In [1]:
import scipy.optimize as spicy
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def myfunction(x, a, b):
return a*x + b
t = np.linspace(-1, 1, 20)
sigma = 0.3*np.ones_like(t)
y = myfunction(t, 1.0, 10.) + sigma*np.random.normal(0, 1, 20)
In [2]:
fit = spicy.curve_fit(myfunction, t, y, p0=[1.0, 1.0], sigma=sigma)
In [3]:
abest, bbest = fit[0]
plt.scatter(t, y)
plt.plot(t, myfunction(t, abest, bbest))
Out[3]:
In [5]:
print fit[0]
In [ ]: