Python MATLAB相当于d

2024-05-14 02:45:45 发布

您现在位置:Python中文网/ 问答频道 /正文

正如标题所示,我正在寻找一个等价的函数,或者一个关于如何实现deval在MATLAB中但在Python中所做的相同事情的建议。在

代码:

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

#define model function that returns ds/dt, di/dt/ and dr/dt

def epidemic_model(state, t):
     s, i, r = state
     d_s = -0.06 * s * i
     d_i = 0.06 *s * i - 7*i
     d_r = 7 * i
     return [d_s, d_i, d_r]


t = np.arange(0, 1, 0.01)
init_state = [990, 10, 0]

state = odeint(epidemic_model, init_state, t)
plt.xlabel('time')
plt.ylabel('population') 
plt.plot(t, state)

现在我的任务是找出感染人群和恢复人群的数量是相同的。

我会在MATLAB中使用deval来做这个,我正在寻找一个Python版本。在


Tags: import标题modelinitasnpdtplt
1条回答
网友
1楼 · 发布于 2024-05-14 02:45:45

检查下面sympy包中的dsolve函数:

http://docs.sympy.org/latest/modules/solvers/ode.html#dsolve

Solves any (supported) kind of ordinary differential equation and system of ordinary differential equations.

另外,使用integrate.solve_ivp程序包中的integrate.solve_ivp求解常微分方程组:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html#scipy-integrate-solve-ivp

This function numerically integrates a system of ordinary differential equations given an initial value

相关问题 更多 >