numpy - Why are non-integer exponents causing nan's to show up in Python? -


i trying numerically solve lane-emden equation in python using scipy.integrate.ode class.

for reason, code works integer values of n (the polytropic index) such 3, not non-integer values such 2.9 , 3.1.

i getting runtime warning, "7: runtimewarning: invalid value encountered in double_scalars" , print statement "print f0, f1" shows several values nan's when n not integer.

from scipy.integrate import ode import numpy np  def rhs(zet, u, n):     x = u[0] # theta     y = u[1] # phi     f0 = -u[1]/(zet**2)     f1 = (u[0]**(n))*(zet**2)     print f0, f1     return np.array([f0,f1])  r = ode(rhs).set_integrator("vode", method="adams", atol=1.e-13, rtol=1.e-13, nsteps=15000, order=12)  y0 = np.array([1.,0.]) zeta0 = 0.000001 r.set_initial_value(y0, zeta0)  n=3.1 r.set_f_params(n)  dzeta = 0.000001 zeta = [zeta0] theta = [y0[0]] while r.successful() , r.y[0] > 0.0:     r.integrate(r.t + dzeta)     zeta.append(r.t)     theta.append(r.y[0]) 

what causing issue?


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -