#10251: Bessel functions of real argument have small imaginary component when
scipy
is used
-------------------------+--------------------------------------------------
Reporter: jvkersch | Owner: jason, jkantor
Type: defect | Status: new
Priority: major | Milestone:
Component: numerical | Keywords: bessel, scipy, complex
Author: | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
-------------------------+--------------------------------------------------
When the scipy algorithm is used to compute the Bessel I, J, Y, K
function, the return value often has a small imaginary component (even
though the argument is real):
{{{
sage: bessel_J(5, 1.5)
0.00179942176736061
sage: bessel_J(5, 1.5, algorithm='scipy')
0.00179942176736000 + 4.40731221543000e-19*I
}}}
This does not seem to be a problem with scipy, but is a result of the way
in which scipy is called: the argument is first converted into a complex
number, and then the corresponding function is called:
{{{
sage: import scipy.special
sage: scipy.special.jv(5, 1.5)
0.0017994217673606115
sage: scipy.special.jv(5, complex(1.5, 0.0))
(0.0017994217673606126+4.4073122154284958e-19j)
}}}
One annoying consequence of this behavior is that straightforward plotting
of the bessel functions becomes problematic when the scipy algorithm is
used (the command below works fine when another algorithm is used):
{{{
sage: Bessel(5, typ='J', algorithm='scipy').plot(1, 10)
verbose 0 (3989: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 200 points.
verbose 0 (3989: plot.py, generate_plot_points) Last error message:
'unable to simplify to float approximation'
}}}
The present patch simply remedies this by adding a few lines to
`bessel_{I, J, K, Y}` to check whether the input was real, and if so, to
take the real part of the return value. This is definitely the easiest
solution, but maybe a better one exists based on how Sage calls scipy.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10251>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.