python non linear ODE with 2 variables

有些话、适合烂在心里 提交于 2019-12-12 01:26:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!