Documentation

# legendreP

Legendre polynomials

## Syntax

``legendreP(n,x)``

## Description

example

````legendreP(n,x)` returns the `n`th degree Legendre polynomial at `x`.```

## Examples

### Find Legendre Polynomials for Numeric and Symbolic Inputs

Find the Legendre polynomial of degree `3` at `5.6`.

`legendreP(3,5.6)`
```ans = 430.6400```

Find the Legendre polynomial of degree `2` at `x`.

```syms x legendreP(2,x)```
```ans = (3*x^2)/2 - 1/2```

If you do not specify a numerical value for the degree `n`, the `legendreP` function cannot find the explicit form of the polynomial and returns the function call.

```syms n legendreP(n,x)```
```ans = legendreP(n, x)```

### Find Legendre Polynomial with Vector and Matrix Inputs

Find the Legendre polynomials of degrees `1` and `2` by setting `n = [1 2]`.

```syms x legendreP([1 2],x)```
```ans = [ x, (3*x^2)/2 - 1/2]```

`legendreP` acts element-wise on `n` to return a vector with two elements.

If multiple inputs are specified as a vector, matrix, or multidimensional array, the inputs must be the same size. Find the Legendre polynomials where input arguments `n` and `x` are matrices.

```n = [2 3; 1 2]; xM = [x^2 11/7; -3.2 -x]; legendreP(n,xM)```
```ans = [ (3*x^4)/2 - 1/2, 2519/343] [ -16/5, (3*x^2)/2 - 1/2]```

`legendreP` acts element-wise on `n` and `x` to return a matrix of the same size as `n` and `x`.

### Differentiate and Find Limits of Legendre Polynomials

Use `limit` to find the limit of a Legendre polynomial of degree `3` as `x` tends to -∞.

```syms x expr = legendreP(4,x); limit(expr,x,-Inf)```
```ans = Inf```

Use `diff` to find the third derivative of the Legendre polynomial of degree `5`.

```syms n expr = legendreP(5,x); diff(expr,x,3)```
```ans = (945*x^2)/2 - 105/2```

### Find Taylor Series Expansion of Legendre Polynomial

Use `taylor` to find the Taylor series expansion of the Legendre polynomial of degree `2` at ```x = 0```.

```syms x expr = legendreP(2,x); taylor(expr,x)```
```ans = (3*x^2)/2 - 1/2```

### Plot Legendre Polynomials

Plot Legendre polynomials of orders `1` through `4`.

```syms x y fplot(legendreP(1:4, x)) axis([-1.5 1.5 -1 1]) grid on ylabel('P_n(x)') title('Legendre polynomials of degrees 1 through 4') legend('1','2','3','4','Location','best')```

### Find Roots of Legendre Polynomial

Use `vpasolve` to find the roots of the Legendre polynomial of degree `7`.

```syms x roots = vpasolve(legendreP(7,x) == 0)```
```roots = -0.94910791234275852452618968404785 -0.74153118559939443986386477328079 -0.40584515137739716690660641207696 0 0.40584515137739716690660641207696 0.74153118559939443986386477328079 0.94910791234275852452618968404785```

## Input Arguments

collapse all

Degree of polynomial, specified as a nonnegative number, vector, matrix, multidimensional array, or a symbolic number, vector, matrix, function, or multidimensional array. All elements of nonscalar inputs should be nonnegative integers or symbols.

Input, specified as a number, vector, matrix, multidimensional array, or a symbolic number, vector, matrix, function, or multidimensional array.

## More About

collapse all

### Legendre Polynomial

• The Legendre polynomials are defined as

`$P\left(n,x\right)=\frac{1}{{2}^{n}n!}\frac{{d}^{n}}{d{x}^{n}}{\left({x}^{2}-1\right)}^{n}.$`
• The Legendre polynomials satisfy the recursion formula

`$\begin{array}{l}P\left(n,x\right)=\frac{2n-1}{n}xP\left(n-1,x\right)-\frac{n-1}{n}P\left(n-2,x\right),\\ \text{where}\\ P\left(0,x\right)=1\\ P\left(1,x\right)=x.\end{array}$`
• The Legendre polynomials are orthogonal on the interval [-1,1] with respect to the weight function w(x) = 1, where

• The relation with Gegenbauer polynomials G(n,a,x) is

`$P\left(n,x\right)=G\left(n,\frac{1}{2},x\right).$`
• The relation with Jacobi polynomials P(n,a,b,x) is

`$P\left(n,x\right)=P\left(n,0,0,x\right).$`

## See Also

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos