The LEGENDRE function returns the value of the associated Legendre polynomial . The associated Legendre functions are solutions to the differential equation: with orthogonality constraints: The Legendre polynomials are the solutions to the Legendre equation with m = 0. For positive m, the associated Legendre functions can be written in terms of the Legendre polynomials as: Associated polynomials for negative m are related to positive m by: LEGENDRE is based on the routine plgndr described in section 6.8 of Numerical Recipes in C: The Art of Scientific Computing (Second Edition), published by Cambridge University Press, and is used by permission.

## Examples

### Example 1

Compute the value of the Legendre polynomial at the following X values:

`; Define the parametric X values: `
`X = [-0.75, -0.5, -0.25, 0.25, 0.5, 0.75]; Compute the Legendre polynomial of order L=2:`
`result = LEGENDRE(X, 2); Print the result:`
`PRINT, result`

The result of this is:

` 0.343750 -0.125000 -0.406250 -0.406250 -0.125000  0.343750`

### Example 2

Compute the value of the associated Legendre polynomial at the same X values:

`; Compute the associated Legendre polynomial of order L=2, M=1:`
`result = LEGENDRE(X, 2, 1)`
`; Print the result:`
`PRINT, result`

IDL prints:

` 1.48824  1.29904  0.726184  -0.726184  -1.29904  -1.48824`

This is the exact solution vector to six-decimal accuracy.

## Syntax

Result = LEGENDRE( X, L [, M] [, /DOUBLE] )

## Return Value

If all arguments are scalar, the function returns a scalar. If all arguments are arrays, the function matches up the corresponding elements of X, L, and M, returning an array with the same dimensions as the smallest array. If one argument is a scalar and the other arguments are arrays, the function uses the scalar value with each element of the arrays, and returns an array with the same dimensions as the smallest input array.

If any of the arguments are double-precision or if the DOUBLE keyword is set, the result is double-precision, otherwise the result is single-precision.

## Arguments

### X

The expression for which is evaluated. Values for X must be in the range –1 ≤≤ 1.

### L

An integer scalar or array, L≥ 0, specifying the order l of . If L is of type float, it will be truncated.

### M

An integer scalar or array, –LML, specifying the order m of . If M is not specified, then the default M = 0 is used and the Legendre polynomial, Pl(x), is returned. If M is of type float, it will be truncated.

## Keywords

### DOUBLE

Set this keyword to force the computation to be done in double-precision arithmetic.

## Version History

 5.4 Introduced