Is your function usable?
def mplegp(n,m,x):
  V=mpmath.legenp(n,m,x)
  return float(V.real)+I*float(V.imag)
sage: time plot(lambda x:mplegp(2.1,0,x).real(),(x,-1,1))
CPU times: user 0.87 s, sys: 0.00 s, total: 0.87 s
Wall time: 0.87 s


On 13 Kwi, 19:48, 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.
>
> 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

-- 
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

Reply via email to