Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 4125 by [email protected]: Issues with Bessel functions
http://code.google.com/p/sympy/issues/detail?id=4125

I am using version 0.7.2 and have identified three problems involving the Bessel functions. These were found in association with trying to solve the ODE -y"/2+y/x=0

-----------------------------------------------------------------------

1) sympy appears to be unable to solve this ODE.

from sympy import *
x = Symbol('x')
y = Function('y')
dsolve(-Derivative(y(x),x,x)/2+y(x)/x,y(x))

Traceback (most recent call last):
  File "<input>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/sympy/solvers/ode.py", line 528, in dsolve
    raise NotImplementedError("dsolve: Cannot solve " + str(eq))
NotImplementedError: dsolve: Cannot solve -Derivative(y(x), x, x)/2 + y(x)/x

Mathematica gives the two solutions, which I will denote as y1,y2 as
y1 = sqrt[x] BesselI[1,sqrt[8x]]
y2 = sqrt[x] BesselK[1,sqrt[8x]]

----------------------------------------------------------------------

2) sympy seems to have a problem with taking the following limit

limit(x*diff(y1,x,x)/y1,x,0) # This should equal 2 for any x>=0

sympy returns -oo (same for y2)

You do get the right answer using

limit(x*diff(a1,x,x)/a1,x,1).evalf() # this returns 2

limit(x*diff(a1,x,x)/a1,x,1e-16).evalf() # this is off by about 5%

3) lambdify has trouble with Bessel functions when running a script.

The following code works fine in bpython

import sympy as sy
import numpy as np

if __name__ == '__main__':

    x = sy.Symbol('x')
    y = sy.exp(x)
    z = sy.besselj(1,x)
    print(y)
    print(z)

    Y = sy.lambdify(x,y,'numpy')

    print(Y(0))

    Z = sy.lambdify(x,z,'numpy')

    print(Z(0))

However, if I save the script (attached) and run it the output is

exp(x)
besselj(1, x)
1.0
Traceback (most recent call last):
  File "lambidfy_bessel.py", line 18, in <module>
    print(Z(0))
  File "<string>", line 1, in <lambda>
NameError: global name 'besselj' is not defined




Attachments:
        lambidfy_bessel.py  260 bytes

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy-issues.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to