python画微分方程图像_如何在python中为微分方程图添加参数滑块?

我正在用python绘制微分方程组

dldt = a*l - b*l*p

dpdt = -c*p + d*l*p

在Jupyter笔记本里。如何在绘图中添加交互式滑块,以调整微分方程中的常量参数?

我试过根据这本Jupyter笔记本添加交互式滑块:

https://ipywidgets.readthedocs.io/en/stable/examples/Lorenz%20Differential%20Equations.html

但是我不熟悉在python中求解和绘制微分方程,我不知道如何修改它,使其能够与参数a、b、c和d交互。我能得到的最好的结果是根据下面的代码绘制静态图。

from scipy.integrate import odeint

import matplotlib.pyplot as plt

from IPython.html.widgets import *

import ipywidgets as wg

from IPython.display import display

from numpy import pi

def f(s, t):

a = 1

b = 1

c = 1

d = 0.5

l = s[0]

p = s[1]

dldt = a*l - b*l*p

dpdt = -c*p + d*l*p

return [dldt, dpdt]

t = np.arange(0,10*pi,0.01)

s0=[0.1,5]

s = odeint(f, s0, t)

plt.plot(t,s[:,0],'r-', linewidth=2.0)

plt.plot(t,s[:,1],'b-', linewidth=2.0)

plt.xlabel("day in menstrual cycle")

plt.ylabel("concentration (ng/mL)")

plt.legend(["LH","P"])

plt.show()

我想要的是一个像静态图一样开始的图,但也有参数a、b、c和d的滑块,允许您在更改它们的值时更改该图。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值