python - Solve a system of differential equations using Euler's method -


i'm trying solve system of ordinary differential equations euler's method, when try print velocity get

runtimewarning: overflow encountered in double_scalars 

and instead of printing numbers nan (not number). think problem might when defining acceleration, don't know sure, appreciate if me.

from numpy import * math import pi,exp  d=0.0005*10**-6 a=[]  while d<1.0*10**-6 :     d=d*2     a.append(d)  d=array(a)  def a_particula (d,x, v, t):     cc=((1.00+((2.00*lam)/d))*(1.257+(0.400*exp((-1.10*d)/(2.00*lam)))))     return (g-((densaire*g)/densparticula)-((mu*18.0*v)/(cc*densparticula*  (d**2.00))))  def euler (acel,d, x, v, tv, n=15):     nv, xv, vv = tv.size, zeros_like(tv), zeros_like(tv)     xv[0], vv[0] = x, v     k in range(1, nv):         t, dt = tv[k-1], (tv[k]-tv[k-1])/float(n)         in range(n):             = acel(d,x, v, t)             t, v = t+dt, v+a*dt             x = x+v*dt         xv[k], vv[k] = x, v     return (xv, vv)  g=(9.80)     densaire= 1.225          lam=0.70*10**-6          densparticula=1000.00 mu=(1.785*10**-5)        tv = linspace(0, 5, 50) x, v = 0, 0 #initial conditions   j in range(len(d)):      xx, vv = euler(a_particula, d[j], x, v, tv)      print(d[j],xx,vv) 

in future helpful if included full warning message in question - contain line problem occurs:

tmp/untitled.py:15: runtimewarning: overflow encountered in double_scalars   return (g-((densaire*g)/densparticula)-((mu*18.0*v)/(cc*densparticula*  (d**2.00)))) 

overflow occurs when magnitude of variable exceeds largest value can represented. in case, double_scalars refers 64 bit float, has maximum value of:

print(np.finfo(float).max) # 1.79769313486e+308 

so there scalar value in expression:

(g-((densaire*g)/densparticula)-((mu*18.0*v)/(cc*densparticula*  (d**2.00)))) 

that exceeding ~1.79e308. find out one, can use np.errstate raise floatingpointerror when occurs, catch , start python debugger:

    ...      errstate(over='raise'):         try:             ret = (g-((densaire*g)/densparticula)-((mu*18.0*v)/(cc*densparticula*  (d**2.00))))         except floatingpointerror:             import pdb             pdb.set_trace()         return ret     ... 

from within debugger can check values of various parts of expression. overflow seems occur in:

(mu*18.0*v)/(cc*densparticula*  (d**2.00)) 

the first time warning occurs, (cc*densparticula* (d**2.00) evaluates 2.3210168586496022e-12, whereas (mu*18.0*v) evaluates -9.9984582297025182e+299.

basically dividing large number small number, , magnitude of result exceeding maximum value can represented. might problem math, or might inputs function not reasonably scaled.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -