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.8: June, 2000
61 Copyright 1984, 1987, 2000 by Stephen L. Moshier
66 extern double sqrt ( double );
67 extern double fabs ( double );
68 extern double sin ( double );
69 extern double cos ( double );
70 extern double asin ( double );
71 extern double tanh ( double );
72 extern double sinh ( double );
73 extern double cosh ( double );
74 extern double atan ( double );
75 extern double exp ( double );
77 double sqrt(), fabs(), sin(), cos(), asin(), tanh();
78 double sinh(), cosh(), atan(), exp();
80 extern double PIO2, MACHEP;
82 int ellpj( u, m, sn, cn, dn, ph )
84 double *sn, *cn, *dn, *ph;
86 double ai, b, phi, t, twon;
91 /* Check for special cases */
93 if( m < 0.0 || m > 1.0 )
95 mtherr( "ellpj", DOMAIN );
106 ai = 0.25 * m * (u - t*b);
110 *dn = 1.0 - 0.5*m*t*t;
114 if( m >= 0.9999999999 )
121 *sn = t + ai * (twon - u)/(b*b);
122 *ph = 2.0*atan(exp(u)) - PIO2 + ai*(twon - u)/b;
124 *cn = phi - ai * (twon - u);
125 *dn = phi + ai * (twon + u);
137 while( fabs(c[i]/a[i]) > MACHEP )
141 mtherr( "ellpj", OVERFLOW );
146 c[i] = ( ai - b )/2.0;
148 a[i] = ( ai + b )/2.0;
155 /* backward recurrence */
156 phi = twon * a[i] * u;
159 t = c[i] * sin(phi) / a[i];
161 phi = (asin(t) + phi)/2.0;