3 * Jacobian Elliptic Functions
9 * float 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 * IEEE sn 10000 1.7e-6 2.2e-7
44 * IEEE cn 10000 1.6e-6 2.2e-7
45 * IEEE dn 10000 1.4e-3 1.9e-5
46 * IEEE phi 10000 3.9e-7* 6.7e-8*
48 * Peak error observed in consistency check using addition
49 * theorem for sn(u+v) was 4e-16 (absolute). Also tested by
50 * the above relation to the incomplete elliptic integral.
51 * Accuracy deteriorates when u is large.
59 Cephes Math Library Release 2.2: July, 1992
60 Copyright 1984, 1987, 1992 by Stephen L. Moshier
61 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
65 extern double PIO2F, MACHEPF;
67 #define fabsf(x) ( (x) < 0 ? -(x) : (x) )
70 float sqrtf(float), sinf(float), cosf(float), asinf(float), tanhf(float);
71 float sinhf(float), coshf(float), atanf(float), expf(float);
73 float sqrtf(), sinf(), cosf(), asinf(), tanhf();
74 float sinhf(), coshf(), atanf(), expf();
78 int ellpjf( float uu, float mm,
79 float *sn, float *cn, float *dn, float *ph )
81 int ellpjf( uu, mm, sn, cn, dn, ph )
83 float *sn, *cn, *dn, *ph;
86 float u, m, ai, b, phi, t, twon;
92 /* Check for special cases */
94 if( m < 0.0 || m > 1.0 )
96 mtherr( "ellpjf", DOMAIN );
103 ai = 0.25 * m * (u - t*b);
107 *dn = 1.0 - 0.5*m*t*t;
118 *sn = t + ai * (twon - u)/(b*b);
119 *ph = 2.0*atanf(expf(u)) - PIO2F + ai*(twon - u)/b;
121 *cn = phi - ai * (twon - u);
122 *dn = phi + ai * (twon + u);
134 while( fabsf( (c[i]/a[i]) ) > MACHEPF )
138 /* mtherr( "ellpjf", OVERFLOW );*/
143 c[i] = 0.5 * ( ai - b );
145 a[i] = 0.5 * ( ai + b );
151 /* backward recurrence */
152 phi = twon * a[i] * u;
155 t = c[i] * sinf(phi) / a[i];
157 phi = 0.5 * (asinf(t) + phi);