Or: sage: import sage.libs.mpmath.all as mpmath sage: V=mpmath.call(mpmath.legenp,2.1,0,-2);V 5.83105230126368 + 1.89579005740338*I sage: type(V) <type 'sage.rings.complex_number.ComplexNumber'>
On 13 Kwi, 23:45, Fredrik Johansson <fredrik.johans...@gmail.com> wrote: > On Apr 13, 7:48 pm, ObsessiveMathsFreak > > > > <obsessivemathsfr...@gmail.com> wrote: > > On Apr 12, 8:52 pm, ObsessiveMathsFreak > > > <obsessivemathsfr...@gmail.com> wrote: > > > On Apr 12, 3:51 am, kcrisman <kcris...@gmail.com> wrote: > > > > > > > Or simply legendre_P, legendre_Q > > > > > > Unfortunately, these functions do not support non integer values of n, > > > > > i.e. they don't support generalised legendre functions, which is what > > > > > I need. > > > > > Are gen_legendre_P and gen_legendre_Q okay? These are all used from > > > > Maxima, as I recall. > > > > > - kcrisman > > > > They worked and were a _lot_ faster. Thanks! > > > > sage: time plot([lambda x: P(n,0,x), lambda x: Q(n,0,x)], > > > (x,-1,1),ymin=-2,ymax=2) > > > sage: time plot([gen_legendre_P(n,0,x), gen_legendre_Q(n,0,x)], > > > (x,-1,1),ymin=-2,ymax=2) > > > Time: CPU 3.79 s, Wall: 3.80 s > > > Time: CPU 0.32 s, Wall: 0.41 s > > > Actually, it appears I was mistaken. gen_legendre_P does not appear to > > work for non integral n at least > > > gen_legendre_P(2.1,0,1) > > TypeError: Attempt to coerce non-integral RealNumber to Integer > > > I think I must have been running the test with integer values for n. > > In fact the code for gen_legendre_P explicitly states that it is only > > valid for integer values of n. > > As currently implemented, the mpmath Legendre functions are likely to > be slow for integer parameters and fast (relatively speaking) for > noninteger parameters. So you may consider using the Maxima functions > (or something else) for integer parameters and the mpmath functions > for noninteger parameters. > > > mpmath still works, but it seems to be a bit awkward to translate the > > result from class mpc to a normal sage value. > > > float(mpmath.legenp(2.1,0,-2)) > > TypeError: float() argument must be a string or a number > > > You have to be pretty roundabout with things > > > V=mpmath.legenp(2.1,0,-2) > > z=float(V.real)+I*float(V.imag) > > z > > 5.83105230126 + 1.8957900574*I > > Of course float() won't work when the result is complex. Just use > complex(). > > Alternatively, if you want Sage numbers, check out the functions call, > sage_to_mpmath, mpmath_to_sage in sage.libs.mpmath.all. > > Fredrik -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org