forked from polarch/Spherical-Harmonic-Transform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
legendre2.m
37 lines (31 loc) · 912 Bytes
/
legendre2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function Lx = legendre2(N, x)
%LEGENDRE2 Same as matlab Legendre extended for negative orders m<0.
%
% Pn(-m)(x) = (-1)^m * (n-m)!/(n+m)! * Pnm(x), for -m<0
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% LEGENDRE2.M - 10/10/2013
% Archontis Politis, [email protected]
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Lx = legendre(N, x);
if N ~= 0
m = (0:N)';
norm = (-1).^m .* factorial(N-m)./factorial(N+m);
if isrow(x)
dimx = fliplr(size(x));
else
dimx = size(x);
end
Lx_neg = repmat(norm, [1 dimx]) .* Lx;
% I'm sure there a better way for this
ndimx = ndims(x);
str_dims = [];
for k=1:ndimx
str_dims = [str_dims ', :'];
end
% throw away first row and flip row order
eval(['Lx_neg = Lx_neg(end:-1:2' str_dims ');'])
Lx = [Lx_neg; Lx];
end