1 /*
2 * Licensed to the Hipparchus project under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The Hipparchus project licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.hipparchus.special.elliptic.jacobi;
18
19 import org.hipparchus.complex.Complex;
20 import org.hipparchus.special.elliptic.legendre.LegendreEllipticIntegral;
21 import org.hipparchus.util.FastMath;
22 import org.hipparchus.util.MathUtils;
23
24 /** Algorithm for computing the principal Jacobi functions for complex parameter m.
25 * @since 2.0
26 */
27 class ComplexParameter extends FieldJacobiElliptic<Complex> {
28
29 /** Jacobi θ functions. */
30 private final FieldJacobiTheta<Complex> jacobiTheta;
31
32 /** Quarter period K. */
33 private final Complex bigK;
34
35 /** Quarter period iK'. */
36 private final Complex iBigKPrime;
37
38 /** Real periodic factor for K. */
39 private final double rK;
40
41 /** Imaginary periodic factor for K. */
42 private final double iK;
43
44 /** Real periodic factor for iK'. */
45 private final double rKPrime;
46
47 /** Imaginary periodic factor for iK'. */
48 private final double iKPrime;
49
50 /** Value of Jacobi θ functions at origin. */
51 private final FieldTheta<Complex> t0;
52
53 /** Scaling factor. */
54 private final Complex scaling;
55
56 /** Simple constructor.
57 * @param m parameter of the Jacobi elliptic function
58 */
59 ComplexParameter(final Complex m) {
60
61 super(m);
62
63 // compute nome
64 final Complex q = LegendreEllipticIntegral.nome(m);
65
66 // compute periodic factors such that
67 // z = 4 K [rK Re(z) + iK Im(z)] + 4i K' [rK' Re(z) + iK' Im(z)]
68 bigK = LegendreEllipticIntegral.bigK(m);
69 iBigKPrime = LegendreEllipticIntegral.bigKPrime(m).multiplyPlusI();
70 final double inverse = 0.25 /
71 (bigK.getRealPart() * iBigKPrime.getImaginaryPart() -
72 bigK.getImaginaryPart() * iBigKPrime.getRealPart());
73 this.rK = iBigKPrime.getImaginaryPart() * inverse;
74 this.iK = iBigKPrime.getRealPart() * -inverse;
75 this.rKPrime = bigK.getImaginaryPart() * -inverse;
76 this.iKPrime = bigK.getRealPart() * inverse;
77
78 // prepare underlying Jacobi θ functions
79 this.jacobiTheta = new FieldJacobiTheta<>(q);
80 this.t0 = jacobiTheta.values(m.getField().getZero());
81 this.scaling = bigK.reciprocal().multiply(MathUtils.SEMI_PI);
82
83 }
84
85 /** {@inheritDoc}
86 * <p>
87 * The algorithm for evaluating the functions is based on {@link FieldJacobiTheta
88 * Jacobi theta functions}.
89 * </p>
90 */
91 @Override
92 public FieldCopolarN<Complex> valuesN(Complex u) {
93
94 // perform argument reduction
95 final double cK = rK * u.getRealPart() + iK * u.getImaginaryPart();
96 final double cKPrime = rKPrime * u.getRealPart() + iKPrime * u.getImaginaryPart();
97 final Complex reducedU = u.linearCombination(1.0, u,
98 -4 * FastMath.rint(cK), bigK,
99 -4 * FastMath.rint(cKPrime), iBigKPrime);
100
101 // evaluate Jacobi θ functions at argument
102 final FieldTheta<Complex> tZ = jacobiTheta.values(reducedU.multiply(scaling));
103
104 // convert to Jacobi elliptic functions
105 final Complex sn = t0.theta3().multiply(tZ.theta1()).divide(t0.theta2().multiply(tZ.theta4()));
106 final Complex cn = t0.theta4().multiply(tZ.theta2()).divide(t0.theta2().multiply(tZ.theta4()));
107 final Complex dn = t0.theta4().multiply(tZ.theta3()).divide(t0.theta3().multiply(tZ.theta4()));
108
109 return new FieldCopolarN<>(sn, cn, dn);
110
111 }
112
113 }