0

I have a system of two differential equations:

  1. dri/dt=tan(al)
  2. dal/dt=(vz-C_alz)/C_aln

with vz is as known as a expression which only depends on l, C_alz and C_aln are two expressions of variable ri and al (These mathematical expressions are showed in the code below). Now i want to use Odeint in python to solve these two differential equations with two known initial value ri(0)=2.5, al(0)=0.1, and get ri(l) and al(l) in range of l[0, 36, 100]`

from sympy import sqrt, sin, cos, tan, atan
import matplotlib.pyplot as pl
import numpy as np
from scipy.integrate import odeint

def func(w,l):
    ri, al = w    
    C_aln= 0.0240566430653894*ri*sin(al + 11) - 3.8*sqrt((-sin(al + 11) + 1)/(1 + 3.8*sqrt(2)/ri))*(-ri**2/2401 + 1)*cos(al + 11)/(-sin(al + 11) + 1)
    C_alz= -484*ri**2/1097257 + (-0.00633069554352353*ri*sqrt((-sin(al + 11) + 1)/(1 + 3.8*sqrt(2)/ri)) - 0.0240566430653894*cos(al + 11) + 14.44*sqrt(2)*sqrt((-sin(al + 11) + 1)/(1 + 3.8*sqrt(2)/ri))*(-ri**2/2401 + 1)/(ri**2*(1 + 3.8*sqrt(2)/ri)))*tan(al) + 1
    vz=(-0.00420681454754192*l**2 + 0.180893025544303*l - 0.960117265980565)*(-0.00633069554352353*sqrt((sin(atan(0.00420681454754192*l**2 - 0.180893025544303*l + 0.960117265980565) - 11) + 1)/(1 + 3.8*sqrt(2)/(-0.00140227151584731*l**3 + 0.0904465127721514*l**2 - 0.960117265980565*l + 5.26992086596417)))*(-0.00140227151584731*l**3 + 0.0904465127721514*l**2 - 0.960117265980565*l + 5.26992086596417) + 14.44*sqrt(2)*sqrt((sin(atan(0.00420681454754192*l**2 - 0.180893025544303*l + 0.960117265980565) - 11) + 1)/(1 + 3.8*sqrt(2)/(-0.00140227151584731*l**3 + 0.0904465127721514*l**2 - 0.960117265980565*l + 5.26992086596417)))*(-(-0.00140227151584731*l**3 + 0.0904465127721514*l**2 - 0.960117265980565*l + 5.26992086596417)**2/2401 + 1)/((1 + 3.8*sqrt(2)/(-0.00140227151584731*l**3 + 0.0904465127721514*l**2 - 0.960117265980565*l + 5.26992086596417))*(-0.00140227151584731*l**3 + 0.0904465127721514*l**2 - 0.960117265980565*l + 5.26992086596417)**2) - 0.0240566430653894*cos(atan(0.00420681454754192*l**2 - 0.180893025544303*l + 0.960117265980565) - 11)) - 484*(-0.00140227151584731*l**3 + 0.0904465127721514*l**2 - 0.960117265980565*l + 5.26992086596417)**2/1097257 + 1
    f=[tan(al), (vz-C_alz)/C_aln]
    return f

init = [2.5, 0.1]
l = np.linspace(0,36,100)
sol=odeint(func, init, l)
pl.figure(1)
pl.plot(l, sol[:,0], color='b')
pl.legend()
pl.show()

My problems are:

only the first three numerical value of ri can be calculated, the other value are zero.

at the same time I get a error message:

Excess work done on this call (perhaps wrong Dfun type).
Run with full_output = 1 to get quantitative information.

anybody can answer my questions:

  1. have Iused the odeint in code correctly ?(I am quite sure the mathematical expressions are correct)
  2. what is wrong with my calculated result and graphic, how can I make the output not full? I have tried to change the parameter of odeint, for example change mxstep, but it doesn't work.
talonmies
  • 70,661
  • 34
  • 192
  • 269
wangmars
  • 29
  • 6
  • 2
    Similar to http://stackoverflow.com/questions/34618488/solving-two-dimension-differential-equations-in-python-with-scipy – hpaulj Jan 05 '16 at 19:53
  • The problem in the other question was that the derivative blew up when the integration variable got too close to 0. I'd suggest testing this over over various `l` ranges. Does it work in certain ranges, but not others? – hpaulj Jan 05 '16 at 22:43

0 Answers0