[SciPy-User] Fitting Differential Equations to a Curve

Pappu Kumar papuu_k@yahoo....
Tue Feb 7 04:43:34 CST 2012

I am trying to fit the differential equation ay' + 
by''=0 to a curve by varying a and b The following code does not work:

from scipy.integrate import odeint
from scipy.optimize import curve_fit
from numpy import linspace, random, array

time = linspace(0.0,10.0,100)
def deriv(time,a,b): 
    dy=lambda y,t : array([ y[1], a*y[0]+b*y[1] ])
    yinit = array([0.0005,0.2]) # initial values
    return Y[:,0]

z = deriv(time, 2, 0.1)
zn = z + 0.1*random.normal(size=len(time))

popt, pcov = curve_fit(deriv, time, zn)
print popt # it only outputs the initial values of a, b!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120207/8948b898/attachment.html 

More information about the SciPy-User mailing list