Legendre polynomials derivative
NickName:Hiddenguy Ask DateTime:2018-10-24T18:42:13

Legendre polynomials derivative

I use this code to create legendre polynomials, from 1st to the 7th order.

N = 4000
xvals = np.linspace(-1, 1, N)

def Legendre(x, n):
    leg = legendre(n)
    P_n = leg(x)
    return P_n

for i in range(1, 8):
    func = Legendre(xvals, i)
    plt.plot(xvals, func, '--', label="n =" + str(i))

It works well, but right now I am struggling with making derivatives from those functions. I decided to switch to numpy to do this, but it is quite poorly described and I stuck with this problem.

Here is the code:

for i in range(1, 8):
    func = np.polynomial.legendre.Legendre.deriv(i)
    print func

UPDATE: Thanks to @James C.

I used his suggestion:

le = np.polynomial.legendre.Legendre((1,2,3,4,5,6,7))

for i in range(1,8):
    print le.deriv(i)

And what I get something like this:

leg([12. 45. 50. 84. 54. 77.])
leg([206. 312. 805. 378. 693.])
leg([ 690. 4494. 1890. 4851.])
leg([ 9345.  5670. 24255.])
leg([ 5670. 72765.])
leg([72765.])
leg([0.])

Unfortunately I am no mathematican, but is it the correct result? I need those derivatives to the equation and at this point I have no idea, how can I put those arrays into.

Libraries: https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.polynomial.legendre.Legendre.deriv.html#numpy.polynomial.legendre.Legendre.deriv

Copyright Notice:Content Author:「Hiddenguy」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52966935/legendre-polynomials-derivative

More about “Legendre polynomials derivative” related questions

Legendre polynomials derivative

I use this code to create legendre polynomials, from 1st to the 7th order. N = 4000 xvals = np.linspace(-1, 1, N) def Legendre(x, n): leg = legendre(n) P_n = leg(x) return P_n for i in

Show Detail

Numerical integration Legendre Polynomials MATLAB

The Legendre polynomials are implemented in MATLAB as vectors, where you also get all the associated Legendre polynomials evaluated at a particular point x. Thus, I don't know how I can use these

Show Detail

Python and associated Legendre polynomials

I have been searching for a python implementation of the associated Legendre polynomials quite a long time and have found nothing satisfying me. There is an implementation in scipy.special, but it ...

Show Detail

Generalized associated Legendre Polynomials

Is there a simple way to calculate the generalized associated Legendre polynomials in Python (article)? I know that you can get the associated Legendre Polynomials using SciPy or pyshtools (articl...

Show Detail

Octave Matrix of discretized Legendre polynomials

I need to get N x columns(L) matrix of legendre polynomials evaluated over L for arbitrary N. Is there a better way of computing the matrix than just explicitly evaluating the polynomial vector fo...

Show Detail

Matlab code optimization for Legendre polynomials

I know Matlab has built-in functions for determining the associated Legendre functions. I want to compute the Legendre polynomials which are a particular case of those ones. I have written my own c...

Show Detail

Boost alternative to gsl_sf_legendre_sphPlm_array() for Legendre polynomials

My understanding is that Boost library is much faster than GSL. I'm now maintaining a code that calls gsl_sf_legendre_sphPlm_array at some point in the calculation to compute Legendre polynomials. ...

Show Detail

Problems with GSL using Legendre polynomials

I'm trying to update an old code that was using a version of GSL with deprecated functions, but I'm having troubles to find how to use the new version of the normalized Legendre polynomials functio...

Show Detail

Orthogonality issue in scipy's legendre polynomials

I recently stumbled upon a curious issue concerning the scipy.special.legendre() (scipy documentation). The legendre polynomials should be pairwise orthogonal. However, when I calculate them over a...

Show Detail

How to calculate associated Legendre polynomials given m and l in Python

The general expression for associated legendre polynomial is given as : I have been looking for a python solution, where given m=0 , I can compute the expression for the polynomial of 'Pl' at the...

Show Detail