50
3 Legendre Polynomials and Legendre Functions
ya = cumprod(ta);
% single summands without z^n
te = ya. * zprod;
% complete series
% check convergency
tres = cumsum(te,2);
%
not for computation
The cumulative sum will give us some information about convergency. Simply
summing up the complete series will shrink the accuracy due to mutual
cancellations. Therefore, we split the total array te for each individual zvalue into its real and imaginary subparts. Each of these subparts is divided
into its positive and negative values. The positive part will be sorted in
ascending order and the negative part in descending order before summing up,
e.g.,
rtz1 = real(te);
% Real and imaginary part
itz1 = imag(te);
for k = 1:length(z)
% Split for single z-values
rtz1s = rtz1(k,:);
itz1s = itz1(k,:);
rtz1p = sum(sort(rtz1s(rtz1s>0)));
% Positive part
rtz1m = sum(sort(rtz1s(rtz1s<=0),’descend’));
% Negative part
itz1p = sum(sort(itz1s(itz1s>0)));
% Positive part
itz1m = sum(sort(itz1s(itz1s<=0),’descend’));
% Negative part
...
end
Special Values
In some cases, we can compute the value of the Legendre function without
computational approximations [1, 3]:
P
μ
ν (0) =
2 μ
√
π
cos
1
2
π(ν + μ)
Γ
ν + μ + 1
2
/Γ
1
2
ν −
1
2
μ + 1
(3.27a)
Q
μ
ν (0) = −2
μ−1 √
π sin
1
2
π(ν + μ)
Γ
ν+μ+1
2
Γ
1
2 ν −
1
2 μ + 1
(3.27b)
P
1
2
ν (cos θ) =
2
π sin θ
cos
ν +
1
2
θ
(3.28a)
3 Legendre Polynomials and Legendre Functions
ya = cumprod(ta);
% single summands without z^n
te = ya. * zprod;
% complete series
% check convergency
tres = cumsum(te,2);
%
not for computation
The cumulative sum will give us some information about convergency. Simply
summing up the complete series will shrink the accuracy due to mutual
cancellations. Therefore, we split the total array te for each individual zvalue into its real and imaginary subparts. Each of these subparts is divided
into its positive and negative values. The positive part will be sorted in
ascending order and the negative part in descending order before summing up,
e.g.,
rtz1 = real(te);
% Real and imaginary part
itz1 = imag(te);
for k = 1:length(z)
% Split for single z-values
rtz1s = rtz1(k,:);
itz1s = itz1(k,:);
rtz1p = sum(sort(rtz1s(rtz1s>0)));
% Positive part
rtz1m = sum(sort(rtz1s(rtz1s<=0),’descend’));
% Negative part
itz1p = sum(sort(itz1s(itz1s>0)));
% Positive part
itz1m = sum(sort(itz1s(itz1s<=0),’descend’));
% Negative part
...
end
Special Values
In some cases, we can compute the value of the Legendre function without
computational approximations [1, 3]:
P
μ
ν (0) =
2 μ
√
π
cos
1
2
π(ν + μ)
Γ
ν + μ + 1
2
/Γ
1
2
ν −
1
2
μ + 1
(3.27a)
Q
μ
ν (0) = −2
μ−1 √
π sin
1
2
π(ν + μ)
Γ
ν+μ+1
2
Γ
1
2 ν −
1
2 μ + 1
(3.27b)
P
1
2
ν (cos θ) =
2
π sin θ
cos
ν +
1
2
θ
(3.28a)
