ComplexParameter.java

  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. import org.hipparchus.complex.Complex;
  19. import org.hipparchus.special.elliptic.legendre.LegendreEllipticIntegral;
  20. import org.hipparchus.util.FastMath;
  21. import org.hipparchus.util.MathUtils;

  22. /** Algorithm for computing the principal Jacobi functions for complex parameter m.
  23.  * @since 2.0
  24.  */
  25. class ComplexParameter extends FieldJacobiElliptic<Complex> {

  26.     /** Jacobi θ functions. */
  27.     private final FieldJacobiTheta<Complex> jacobiTheta;

  28.     /** Quarter period K. */
  29.     private final Complex bigK;

  30.     /** Quarter period iK'. */
  31.     private final Complex iBigKPrime;

  32.     /** Real periodic factor for K. */
  33.     private final double rK;

  34.     /** Imaginary periodic factor for K. */
  35.     private final double iK;

  36.     /** Real periodic factor for iK'. */
  37.     private final double rKPrime;

  38.     /** Imaginary periodic factor for iK'. */
  39.     private final double iKPrime;

  40.     /** Value of Jacobi θ functions at origin. */
  41.     private final FieldTheta<Complex> t0;

  42.     /** Scaling factor. */
  43.     private final Complex scaling;

  44.     /** Simple constructor.
  45.      * @param m parameter of the Jacobi elliptic function
  46.      */
  47.     ComplexParameter(final Complex m) {

  48.         super(m);

  49.         // compute nome
  50.         final Complex q = LegendreEllipticIntegral.nome(m);

  51.         // compute periodic factors such that
  52.         // z = 4 K [rK Re(z) + iK Im(z)] + 4i K' [rK' Re(z) + iK' Im(z)]
  53.         bigK                 = LegendreEllipticIntegral.bigK(m);
  54.         iBigKPrime           = LegendreEllipticIntegral.bigKPrime(m).multiplyPlusI();
  55.         final double inverse = 0.25 /
  56.                                (bigK.getRealPart()      * iBigKPrime.getImaginaryPart() -
  57.                                 bigK.getImaginaryPart() * iBigKPrime.getRealPart());
  58.         this.rK              = iBigKPrime.getImaginaryPart() *  inverse;
  59.         this.iK              = iBigKPrime.getRealPart()      * -inverse;
  60.         this.rKPrime         = bigK.getImaginaryPart()       * -inverse;
  61.         this.iKPrime         = bigK.getRealPart()            *  inverse;

  62.         // prepare underlying Jacobi θ functions
  63.         this.jacobiTheta = new FieldJacobiTheta<>(q);
  64.         this.t0          = jacobiTheta.values(m.getField().getZero());
  65.         this.scaling     = bigK.reciprocal().multiply(MathUtils.SEMI_PI);

  66.     }

  67.     /** {@inheritDoc}
  68.      * <p>
  69.      * The algorithm for evaluating the functions is based on {@link FieldJacobiTheta
  70.      * Jacobi theta functions}.
  71.      * </p>
  72.      */
  73.     @Override
  74.     public FieldCopolarN<Complex> valuesN(Complex u) {

  75.         // perform argument reduction
  76.         final double cK      = rK * u.getRealPart() + iK * u.getImaginaryPart();
  77.         final double cKPrime = rKPrime * u.getRealPart() + iKPrime * u.getImaginaryPart();
  78.         final Complex reducedU = u.linearCombination(1.0,                        u,
  79.                                                     -4 * FastMath.rint(cK),      bigK,
  80.                                                     -4 * FastMath.rint(cKPrime), iBigKPrime);

  81.         // evaluate Jacobi θ functions at argument
  82.         final FieldTheta<Complex> tZ = jacobiTheta.values(reducedU.multiply(scaling));

  83.         // convert to Jacobi elliptic functions
  84.         final Complex sn = t0.theta3().multiply(tZ.theta1()).divide(t0.theta2().multiply(tZ.theta4()));
  85.         final Complex cn = t0.theta4().multiply(tZ.theta2()).divide(t0.theta2().multiply(tZ.theta4()));
  86.         final Complex dn = t0.theta4().multiply(tZ.theta3()).divide(t0.theta3().multiply(tZ.theta4()));

  87.         return new FieldCopolarN<>(sn, cn, dn);

  88.     }

  89. }