function P = legendre_p(n)
- ## Return the nth legendre polynomial.
+ ## Return the `n`th Legendre polynomial.
##
- ## INPUTS:
+ ## INPUT:
##
## * ``n`` - The index of the polynomial that we want.
##
- ## OUTPUTS:
+ ## OUTPUT:
##
## * ``P`` - A polynomial function of one argument.
##
## The second base case.
P = @(x) x;
else
- ## Compute recursively.
+ ## Not one of the base cases, so use the recursive formula.
prev = legendre_p(n-1);
prev_prev = legendre_p(n-2);
P = @(x) (1/n).*( (2*n - 1).*x.*prev(x) - (n-1).*prev_prev(x) );
function P_tilde = legendre_p_tilde(n, a, b)
- ## Return the nth Legendre polynomial scaled to the interval [a,b].
+ ## Return the `n`th Legendre polynomial scaled to the interval [a,b].
##
- ## INPUTS:
+ ## INPUT:
##
## * ``n`` - The index of the polynomial that we want.
##
##
## * ``b`` - The right endpoint of the interval.
##
- ## OUTPUTS:
+ ## OUTPUT:
##
## * ``P_tilde`` - A polynomial function of one argument.
##
## Can't do anything here. Return nothing.
P = NA;
else
- ## Compute the Legendre polynomial over [-1,1] and mangle it.
+ ## Compute the Legendre polynomial over [-1,1] and mangle it to fit
+ ## the interval [a,b].
P = legendre_p(n);
P_tilde = @(x) P( (2/(b-a)).*x + 1 - (2*b)/(b-a) );
end