3
* Jacobian Elliptic Functions
9
* double u, m, sn, cn, dn, phi;
12
* ellpj( u, m, _&sn, _&cn, _&dn, _&phi );
19
* Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m),
20
* and dn(u|m) of parameter m between 0 and 1, and real
23
* These functions are periodic, with quarter-period on the
24
* real axis equal to the complete elliptic integral
27
* Relation to incomplete elliptic integral:
28
* If u = ellik(phi,m), then sn(u|m) = sin(phi),
29
* and cn(u|m) = cos(phi). Phi is called the amplitude of u.
31
* Computation is by means of the arithmetic-geometric mean
32
* algorithm, except when m is within 1e-9 of 0 or 1. In the
33
* latter case with m close to 1, the approximation applies
34
* only for phi < pi/2.
38
* Tested at random points with u between 0 and 10, m between
41
* Absolute error (* = relative error):
42
* arithmetic function # trials peak rms
43
* DEC sn 1800 4.5e-16 8.7e-17
44
* IEEE phi 10000 9.2e-16* 1.4e-16*
45
* IEEE sn 50000 4.1e-15 4.6e-16
46
* IEEE cn 40000 3.6e-15 4.4e-16
47
* IEEE dn 10000 1.3e-12 1.8e-14
49
* Peak error observed in consistency check using addition
50
* theorem for sn(u+v) was 4e-16 (absolute). Also tested by
51
* the above relation to the incomplete elliptic integral.
52
* Accuracy deteriorates when u is large.
60
Cephes Math Library Release 2.0: April, 1987
61
Copyright 1984, 1987 by Stephen L. Moshier
62
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
67
double sqrt(), fabs(), sin(), cos(), asin(), tanh();
68
double sinh(), cosh(), atan(), exp();
70
extern double PIO2, MACHEP, NAN;
72
int ellpj( u, m, sn, cn, dn, ph )
74
double *sn, *cn, *dn, *ph;
76
double ai, b, phi, t, twon;
81
/* Check for special cases */
83
if( m < 0.0 || m > 1.0 )
85
mtherr( "ellpj", DOMAIN );
96
ai = 0.25 * m * (u - t*b);
100
*dn = 1.0 - 0.5*m*t*t;
104
if( m >= 0.9999999999 )
111
*sn = t + ai * (twon - u)/(b*b);
112
*ph = 2.0*atan(exp(u)) - PIO2 + ai*(twon - u)/b;
114
*cn = phi - ai * (twon - u);
115
*dn = phi + ai * (twon + u);
127
while( fabs(c[i]/a[i]) > MACHEP )
131
mtherr( "ellpj", OVERFLOW );
136
c[i] = ( ai - b )/2.0;
138
a[i] = ( ai + b )/2.0;
145
/* backward recurrence */
146
phi = twon * a[i] * u;
149
t = c[i] * sin(phi) / a[i];
151
phi = (asin(t) + phi)/2.0;