问题
I am trying to solve the Brusselator model, a non-linear ODE, using python. I used to do this with MATLAB but now am building an application with python as a backend. That's why I want to switch ti python.
dx/dt = A + (x^2)(y) - Bx - x
dy/dt = Bx - (x^2)(y)
I have checked stackoverflow and most of examples I found are simple non-linear ODE with a single variable that can be converted into a system of linear equation. [- Sorry for my notation. I don't know how to add latex in stackoverflow]
回答1:
I know this is an old question. Nevertheless, I managed to formulate your question in the code below.
There, I implemented your two differential equations in a single function, that I later integrate through ODEINT module from scypy.
I hope this answer your problem.
Sincerely yours,
import scipy.integrate
import numpy as np
import matplotlib.pyplot as plt
def Integrate(y, t, B, A):
X, Y = y
dX_dt = A + (X**2)*(Y) - B*X - X
dY_dt = B*X - (X**2)*(Y)
return [dX_dt, dY_dt]
A0 = 0.9
B0 = 0.6
X0 = 0.1
Y0 = 0.0
B0 = 0.35
t = np.linspace(0,100, 10000)
solution = scipy.integrate.odeint(Integrate, y0=[X0, Y0], t=t, args=(A0, B0) )
plt.plot(t, solution[:,1], label='solution')
plt.legend()
plt.xlabel('time')
plt.ylabel('Y')
plt.show()
来源:https://stackoverflow.com/questions/41177803/python-non-linear-ode-with-2-variables