I wanna solve a simultaneous differential equation and based on Lorenz equations:
def f(xyz, t, rho, sigma, beta):
x, y, z = xyz
return [sigma * (y - x),
x * (rho - z) - y,
x * y - beta * z]
I Wrote this:
def f(xyz, t, rho, sigma, beta):
x, y, z = xyz
return [sigma * y(t).diff(t) + sigma * x + beta * y -77,
x + rho * y - 61]
So basically I have another differential of y in the first equation and I tried to take derivative but it says:
TypeError: 'numpy.float64' object is not callable"
Can you tell me How can I solve such problems and for second orders of those?
You have a linear system for the derivatives, call them xp, yp
. Fortunately it is triangular, so you can solve it via back-substitution. So first solve for yp
then insert that for xp
.
def f(xy,t):
x,y = xy
yp = 61 - (4*x + y)
xp = 77 - (2*yp + 2*x + 5*x)
return xp,yp
In general you could employ a linear-system solver numpy.linalg.solve
or a more general solver like scipy.optimize.fsolve
to extract the derivatives from a system of implicit equations (as far as possible, DAE - systems of differential-algebraic equations can also have this form).