我想用python解决这样一个ODEs: enter image description here
这是我的代码:
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()
我得到了一个完全错误的结果——模型的解表明它不收敛 为什么我会收到这样的警告? 我怎样才能得到正确的答案?在
计算这个线性系统的特征值
给出结果
^{pr2}$因此,有一个分量以
exp(1.606e+04*t)
的形式增长,它的值10**n
,有时t=0.00014333*n
,这解释了观察到的快速增长。在相关问题 更多 >
编程相关推荐