-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlellippi.m
75 lines (74 loc) · 2.24 KB
/
lellippi.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
%
% lellippi(phi, k, errtol)
%
% Inputs:
%
% phi Input angle vector size 1 or 1xN.
% k Input parameter vector size 1 or 1xN.
% n Input parameter vector size 1 or 1xN.
% errtol Error tolerance for Carlson's algorithms.
%
% Matlab function to compute Legendre's (incomplete) elliptic integral
% Pi(phi, k, n). Uses a vectorized implementation of Carlson's Duplication Algorithms
% for symmetric elliptic integrals as found in "Computing Elliptic
% Integrals by Duplication," by B. C. Carlson, Numer. Math. 33, 1-16 (1979)
% and also found in ACM TOMS Algorithm 577. Section 4 in the paper cited
% here describes how to convert between the symmetric elliptic integrals
% and Legendre's elliptic integrals.
%
% Returns NaN's for any argument values outside input range.
%
function f = lellippi(phi, k, n, errtol)
% Argument checking for vectorization:
lphi = length(phi);
lk = length(k);
ln = length(n);
errflag = logical(0);
if ( ~ ((lphi==lk) & (lphi==ln) & (lk==ln)) )
if ( (lk==1) & (ln==1) )
kvec = k * ones(1,lphi);
nvec = n * ones(1,lphi);
phivec = phi;
elseif ( (lphi==1) & (ln==1) )
phivec = phi * ones(1,lk);
nvec = n * ones(1,lk);
kvec = k;
elseif ( (lphi==lk) & (ln==1) )
nvec = n * ones(1,lphi);
kvec = k;
phivec = phi;
elseif ( (lphi==1) & (lk==1) )
phivec = phi * ones(1,ln);
kvec = k * ones(1,lk);
nvec = n;
elseif ( (lphi==ln) & (lk==1) )
kvec = k * ones(1,lphi);
phivec = phi;
nvec = n;
elseif ( (lk==ln) & (lphi==1) )
phivec = phi * ones(1,lk);
kvec = k;
nvec = n
else
disp('Incompatible input vector dimensions in lellipf!');
errflag = logical(1);
end
else
phivec = phi;
kvec = k;
nvec = n;
end
if (~errflag)
snphi = sin(phivec);
csphi = cos(phivec);
snphi2 = snphi.^2;
csphi2 = csphi.^2;
k2 = kvec.^2;
y = 1.0 - k2.*snphi2;
p = 1.0 + nvec .* snphi2;
onesvec = ones(1,length(phivec));
f = snphi .* rf(csphi2, y, onesvec, errtol) - ...
nvec .* snphi .* snphi2 .* rj(csphi2, y, onesvec, p, errtol) / 3.0;
else
f = NaN;
end