python - ODEintWarning: Illegal input detected (internal error)? -
i want solve odes in python: enter image description here
here code:
import numpy np scipy.integrate import odeint import matplotlib.pyplot plt def cde(y,t,r1,r2,l1,l2,m,c): #define vecter of dependent variables i1,i2,uc = y #define 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 vecter of dependent variables y0 = [0,0,3000] #initialize 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 model sol = odeint(cde, y0, t, args=(r1,r2,l1,l2,m,c)) #plot 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()
the got incorrect results--the solution of model shows doesn't converge why odeintwarning that? how can correct solution?
computing eigenvalues of linear system
dy1=cde([1,0,0],0,r1,r2,l1,l2,m,c) dy2=cde([0,1,0],0,r1,r2,l1,l2,m,c) dy3=cde([0,0,1],0,r1,r2,l1,l2,m,c) np.linalg.eig([dy1,dy2,dy3])
gives result
(array([ -1.63811579e+04, 1.60647105e+04, -1.24999684e+01]), array([[ -6.19266551e-02, -6.11336770e-02, -4.10359481e-01], [ -4.49479256e-04, 4.48809049e-04, 9.11909417e-01], [ 9.98080602e-01, -9.98129487e-01, 5.12941642e-03]]))
so there component grows exp(1.606e+04*t)
, has values 10**n
@ times t=0.00014333*n
explains observed rapid growth.
wiki
Comments
Post a Comment