Hi, I need to find out the (first) derivative of associated Legendre polynomials defined in lpmn(m,n,x). The problem is that I want to derive vs theta where x=cos(theta). For instance, for m=1 & n=0, P_0^1(cos(theta)) = cos(theta) -> P_0^1'(cos(theta)) = -sin(theta) I know that scipy has not symbolic math module (and pythonica seems to be quite old & unmaintained). But I use maxima. So I wonder if it would be possible to run maxima, derive assoc_legendre_p(n,m,cos(theta)) vs. theta and "send" the result to python. How could I do that ? Cheers,
Have you looked into SAGE (sage.scipy.org)? SAGE is written in Python but includes maxima and has some special functions (wrapped from maxima and pari). I'm not excatly sure what your question is, but SAGE might help do what you want. +++++++++++++++++++++++++++++++++++++ fredantispam@free.fr wrote:
Hi,
I need to find out the (first) derivative of associated Legendre polynomials defined in lpmn(m,n,x).
The problem is that I want to derive vs theta where x=cos(theta).
For instance, for m=1 & n=0, P_0^1(cos(theta)) = cos(theta) -> P_0^1'(cos(theta)) = -sin(theta)
I know that scipy has not symbolic math module (and pythonica seems to be quite old & unmaintained).
But I use maxima.
So I wonder if it would be possible to run maxima, derive assoc_legendre_p(n,m,cos(theta)) vs. theta and "send" the result to python.
How could I do that ?
Cheers, _______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
David Joyner a écrit :
Have you looked into SAGE (sage.scipy.org)? SAGE is written in Python but includes maxima and has some special functions (wrapped from maxima and pari). I'm not excatly sure what your question is, but SAGE might help do what you want. Looks like interesting...
But I don't think it can fit my needs (maybe I'm wrong). Thanks anyway. -- Fred.
Hi, I perform the same kind of job with mathematica and python : 1) Compute what you want using mathematica/maxima/... 2) export the result as text in a syntax as close as possible as python once (mathematica can export to C code for instance) 3) Perform tiny modification on the resulting strings so that it corresponds with python syntax. 4) use exec() and that's it. Maybe it is uglly but it is powerfull and simple ;) Xavier.
Hi,
I need to find out the (first) derivative of associated Legendre polynomials defined in lpmn(m,n,x).
The problem is that I want to derive vs theta where x=cos(theta).
For instance, for m=1 & n=0, P_0^1(cos(theta)) = cos(theta) -> P_0^1'(cos(theta)) = -sin(theta)
I know that scipy has not symbolic math module (and pythonica seems to be quite old & unmaintained).
But I use maxima.
So I wonder if it would be possible to run maxima, derive assoc_legendre_p(n,m,cos(theta)) vs. theta and "send" the result to python.
How could I do that ?
Cheers, _______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
-- ############################################ Xavier Gnata CRAL - Observatoire de Lyon 9, avenue Charles André 69561 Saint Genis Laval cedex Phone: +33 4 78 86 85 28 Fax: +33 4 78 86 83 86 E-mail: gnata@obs.univ-lyon1.fr ############################################
On Mon, Aug 07, 2006 at 04:32:17PM +0200, Xavier Gnata wrote:
Hi,
I perform the same kind of job with mathematica and python : 1) Compute what you want using mathematica/maxima/... 2) export the result as text in a syntax as close as possible as python once (mathematica can export to C code for instance) 3) Perform tiny modification on the resulting strings so that it corresponds with python syntax. 4) use exec() and that's it.
Better still: use weave.inline, and pure c code. -- Gaël
On Mon, Aug 07, 2006 at 04:32:17PM +0200, Xavier Gnata wrote:
Hi,
I perform the same kind of job with mathematica and python : 1) Compute what you want using mathematica/maxima/... 2) export the result as text in a syntax as close as possible as python once (mathematica can export to C code for instance) 3) Perform tiny modification on the resulting strings so that it corresponds with python syntax. 4) use exec() and that's it.
Better still: use weave.inline, and pure c code. I read a little about weave.inline. But I don't understand the use of "pure c code". What do you mean ? How can I get the derivative of the associated Legendre polynomial vs
Gael Varoquaux a écrit : theta ? -- Fred.
On Mon, Aug 07, 2006 at 07:59:12PM +0200, fred wrote:
Gael Varoquaux a écrit :
On Mon, Aug 07, 2006 at 04:32:17PM +0200, Xavier Gnata wrote:
Hi,
I perform the same kind of job with mathematica and python : 1) Compute what you want using mathematica/maxima/... 2) export the result as text in a syntax as close as possible as python once (mathematica can export to C code for instance) 3) Perform tiny modification on the resulting strings so that it corresponds with python syntax. 4) use exec() and that's it.
Better still: use weave.inline, and pure c code.
I read a little about weave.inline. But I don't understand the use of "pure c code".
I was talking about Xavier's idea: do step 1 and 2 as he says, and use weave.inline to use the c code generated by mathematica. -- Gaël
http://swiginac.berlios.de/ could be interesting for dealing with symbolic computation -----Original Message----- From: scipy-user-bounces@scipy.org [mailto:scipy-user-bounces@scipy.org] On Behalf Of Gael Varoquaux Sent: Monday, August 07, 2006 8:02 PM To: SciPy Users List Subject: Re: [SciPy-user] symbolic math & scipy (& maxima)... On Mon, Aug 07, 2006 at 07:59:12PM +0200, fred wrote:
Gael Varoquaux a écrit :
On Mon, Aug 07, 2006 at 04:32:17PM +0200, Xavier Gnata wrote:
Hi,
I perform the same kind of job with mathematica and python : 1) Compute what you want using mathematica/maxima/... 2) export the result as text in a syntax as close as possible as python once (mathematica can export to C code for instance) 3) Perform tiny modification on the resulting strings so that it corresponds with python syntax. 4) use exec() and that's it.
Better still: use weave.inline, and pure c code.
I read a little about weave.inline. But I don't understand the use of "pure c code".
I was talking about Xavier's idea: do step 1 and 2 as he says, and use weave.inline to use the c code generated by mathematica. -- Gaël _______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
Jelle Feringa / EZCT Architecture & Design Research a écrit :
could be interesting for dealing with symbolic computation Ok, thanks.
I'm looking for something more "clean" than the one I wrote ;-) Cheers, -- Fred.
Jelle Feringa / EZCT Architecture & Design Research a écrit :
could be interesting for dealing with symbolic computation Ok, sounds good...
But I did not find anything about Legendre associated polynomials. :-( -- Fred.
fred a écrit :
Jelle Feringa / EZCT Architecture & Design Research a écrit :
could be interesting for dealing with symbolic computation
Ok, sounds good...
But I did not find anything about Legendre associated polynomials. :-( One can try to define them :
from scipy.special import * from swiginac import * x = symbol('x') def lpm(m,x): p = (x**2-1)**m return (1./(2**m*factorial(m))*p.diff(x,m)) def lpmn(m,n,x): p = lpm(n,x) return ((-1)**m*(1-x**2)**(m/2.)*p.diff(x,m)) print lpm(2,x)
-0.5+(1.5)*x**2 Ok.
But : u = arange(0,1,0.1) print lpm(2,u) Traceback (most recent call last): File "./essai.py", line 20, in ? print lpm(2,u) File "./essai.py", line 11, in lpm return (1./(2**m*factorial(m))*p.diff(x,m)) AttributeError: 'numpy.ndarray' object has no attribute 'diff' Any suggestion ? Cheers, -- Fred.
Gael Varoquaux a écrit :
I was talking about Xavier's idea: do step 1 and 2 as he says, and use weave.inline to use the c code generated by mathematica.
Ok, I understand better. But maxima only generates fortran code. A little tricky (quick'n'dirty) but it works fine now : def Lmnp(x,y,z,m,n): cmd = "maxima -r 'load(\"specfun\")$fortran(diff(assoc_legendre_p("+str(n)+','+str(m)+",cos(theta)),theta))$\n' | grep -v 'Maxima\|%' | tr [A-Z] [a-z] | sed 's!theta!theta(x,y,z)!g'" foo = getoutput(cmd) return(eval(foo)) Thanks all. -- Fred.
Xavier Gnata a écrit :
Hi,
I perform the same kind of job with mathematica and python : 1) Compute what you want using mathematica/maxima/... 2) export the result as text in a syntax as close as possible as python once (mathematica can export to C code for instance) 3) Perform tiny modification on the resulting strings so that it corresponds with python syntax. 4) use exec() and that's it.
Maybe it is uglly but it is powerfull and simple ;) Hmm, yes, I usually proceed like this ;-) Tricky but it should work.
-- Fred.
participants (6)
-
David Joyner -
fred -
fredantispam@free.fr -
Gael Varoquaux -
Jelle Feringa / EZCT Architecture & Design Research -
Xavier Gnata