1 function P = legendre_p(n)
2 ## Return the nth legendre polynomial.
6 ## * ``n`` - The index of the polynomial that we want.
10 ## * ``P`` - A polynomial function of one argument.
13 ## Can't do anything here. Return nothing.
16 ## One of our base cases.
19 ## The second base case.
22 ## Compute recursively.
23 prev = legendre_p(n-1)
24 prev_prev = legendre_p(n-2)
25 P = @(x) (1/n)*( (2*n - 1)*prev(x) - (n-1)*prev_prev(x) )