%% Associated Legendre Function Values of Vector
% Use the legendre function to operate on a vector and then examine the format of the output.
%
% Calculate the second-degree Legendre function values of a vector.

deg = 2;
x = 0:0.1:0.2;
P = legendre(deg,x)

%
% The format of the output is such that:
% Each row contains the function value for different values of m (the order of the associated Legendre function)
% Each column contains the function value for a different value of x
% \begin{array}{c|ccc}
%  & \mbox{x = 0} & \mbox{x = 0.1} & \mbox{x = 0.2}\\
% \mbox{m = 0} & P_2^0(0) & P_2^0(0.1) & P_2^0(0.2)\\
% \mbox{m = 1} & P_2^1(0) & P_2^1(0.1) & P_2^1(0.2)\\
% \mbox{m = 2} & P_2^2(0) & P_2^2(0.1) & P_2^2(0.2)\\
% \end{array}
%
%
% The equation for the second-degree associated Legendre function P_2^m is
% P_2^m(x) = \left( -1 \right) ^m \left(1-x^2\right)^{m/2} \frac{d^m}{dx^m} \left[ \frac{1}{2} \left(3x^2-1\right)\right] .
% Therefore, the value of P_2^0 \left(0\right) is
% P_2^0(0) = \left[ \frac{1}{2} \left(3x^2-1\right)\right] \vert _{x=0} = -\frac{1}{2}.
% This result agrees with P(1,1) = -0.5000.
% Copyright 2018 The MathWorks, Inc.