View Javadoc
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.CalculusFieldElement;
20  import org.hipparchus.complex.FieldComplex;
21  import org.hipparchus.special.elliptic.legendre.LegendreEllipticIntegral;
22  import org.hipparchus.util.FastMath;
23  
24  /** Algorithm for computing the principal Jacobi functions for complex parameter m.
25   * @param <T> the type of the field elements
26   * @since 2.0
27   */
28  class FieldComplexParameter<T extends CalculusFieldElement<T>> extends FieldJacobiElliptic<FieldComplex<T>> {
29  
30      /** Jacobi θ functions. */
31      private final FieldJacobiTheta<FieldComplex<T>> jacobiTheta;
32  
33      /** Quarter period K. */
34      private final FieldComplex<T> bigK;
35  
36      /** Quarter period iK'. */
37      private final FieldComplex<T> iBigKPrime;
38  
39      /** Real periodic factor for K. */
40      private final T rK;
41  
42      /** Imaginary periodic factor for K. */
43      private final T iK;
44  
45      /** Real periodic factor for iK'. */
46      private final T rKPrime;
47  
48      /** Imaginary periodic factor for iK'. */
49      private final T iKPrime;
50  
51      /** Value of Jacobi θ functions at origin. */
52      private final FieldTheta<FieldComplex<T>> t0;
53  
54      /** Scaling factor. */
55      private final FieldComplex<T> scaling;
56  
57      /** Simple constructor.
58       * @param m parameter of the Jacobi elliptic function
59       */
60      FieldComplexParameter(final FieldComplex<T> m) {
61  
62          super(m);
63  
64          // compute nome
65           final FieldComplex<T> q = LegendreEllipticIntegral.nome(m);
66  
67          // compute periodic factors such that
68          // z = 4K [rK Re(z) + iK Im(z)] + 4K' [rK' Re(z) + iK' Im(z)]
69          bigK            = LegendreEllipticIntegral.bigK(m);
70          iBigKPrime      = LegendreEllipticIntegral.bigKPrime(m).multiplyPlusI();
71          final T inverse = bigK.getRealPart().multiply(iBigKPrime.getImaginaryPart()).
72                            subtract(bigK.getImaginaryPart().multiply(iBigKPrime.getRealPart())).
73                            multiply(4).reciprocal();
74          this.rK         = iBigKPrime.getImaginaryPart().multiply(inverse);
75          this.iK         = iBigKPrime.getRealPart().multiply(inverse).negate();
76          this.rKPrime    = bigK.getImaginaryPart().multiply(inverse).negate();
77          this.iKPrime    = bigK.getRealPart().multiply(inverse);
78  
79          // prepare underlying Jacobi θ functions
80          this.jacobiTheta = new FieldJacobiTheta<>(q);
81          this.t0          = jacobiTheta.values(m.getField().getZero());
82          this.scaling     = bigK.reciprocal().multiply(m.getPi().multiply(0.5));
83  
84      }
85  
86      /** {@inheritDoc}
87       * <p>
88       * The algorithm for evaluating the functions is based on {@link FieldJacobiTheta
89       * Jacobi theta functions}.
90       * </p>
91       */
92      @Override
93      public FieldCopolarN<FieldComplex<T>> valuesN(FieldComplex<T> u) {
94  
95          // perform argument reduction
96          final T cK      = rK.multiply(u.getRealPart()).add(iK.multiply(u.getImaginaryPart()));
97          final T cKPrime = rKPrime.multiply(u.getRealPart()).add(iKPrime.multiply(u.getImaginaryPart()));
98          final FieldComplex<T> reducedU = u.linearCombination(1.0,                                  u,
99                                                              -4 * FastMath.rint(cK.getReal()),      bigK,
100                                                             -4 * FastMath.rint(cKPrime.getReal()), iBigKPrime);
101 
102         // evaluate Jacobi θ functions at argument
103         final FieldTheta<FieldComplex<T>> tZ = jacobiTheta.values(reducedU.multiply(scaling));
104 
105         // convert to Jacobi elliptic functions
106         final FieldComplex<T> sn = t0.theta3().multiply(tZ.theta1()).divide(t0.theta2().multiply(tZ.theta4()));
107         final FieldComplex<T> cn = t0.theta4().multiply(tZ.theta2()).divide(t0.theta2().multiply(tZ.theta4()));
108         final FieldComplex<T> dn = t0.theta4().multiply(tZ.theta3()).divide(t0.theta3().multiply(tZ.theta4()));
109 
110         return new FieldCopolarN<>(sn, cn, dn);
111 
112     }
113 
114 }