python判断非法输入_ODEintWarning:检测到非法输入(内部错误)?

这是我的代码:import numpy as np

from scipy.integrate import odeint

import matplotlib.pyplot as plt

def cde(y,t,r1,r2,l1,l2,m,c):

#define the vecter of dependent variables

i1,i2,uc = y

#define the system of first order equations

dy_dt = [(r2*i2*m/l2 + r1*i1 - uc) / (m**2/l2 - l1),\

(r1*i1 + l1*r2*i2/m - uc) / (m - l1*l2/m),\

i1/c]

return dy_dt

def main():

#initialize the vecter of dependent variables

y0 = [0,0,3000]

#initialize the other variables

r1 = 10 ** (-3)

r2 = 10 ** (-3)

l1 = 20 * 10 ** (-6)

l2 = 80 * 10 ** (-6)

m = 0.9 * (l1 * l2) ** (1/2)

c = 1000 * 10 ** (-6)

t = np.linspace(0, 0.1, 101)

#build the model

sol = odeint(cde, y0, t, args=(r1,r2,l1,l2,m,c))

#plot the figure of solution

plt.plot(t, sol[:, 0], 'b', label='i1')

plt.legend(loc='best')

plt.xlabel('t')

plt.grid()

plt.show()

plt.close()

plt.plot(t, sol[:, 1], 'g', label='i2')

plt.legend(loc='best')

plt.xlabel('t')

plt.grid()

plt.show()

plt.close()

plt.plot(t, sol[:, 1], 'r', label='uc')

plt.legend(loc='best')

plt.xlabel('t')

plt.grid()

plt.show()

plt.close()

main()

我得到了一个完全错误的结果——模型的解表明它不收敛

为什么我会收到这样的警告?

我怎样才能得到正确的答案?在

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值