RcRealDuplication.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.carlson;

  18. import org.hipparchus.util.FastMath;
  19. import org.hipparchus.util.MathArrays;

  20. /** Duplication algorithm for Carlson R<sub>C</sub> elliptic integral.
  21.  * @since 2.0
  22.  */
  23. class RcRealDuplication extends RealDuplication {

  24.     /** Constant term in R<sub>C</sub> polynomial. */
  25.     static final double S0 = 80080;

  26.     /** Coefficient of s² in R<sub>C</sub> polynomial. */
  27.     static final double S2 = 24024;

  28.     /** Coefficient of s³ in R<sub>C</sub> polynomial. */
  29.     static final double S3 = 11440;

  30.     /** Coefficient of s⁴ in R<sub>C</sub> polynomial. */
  31.     static final double S4 = 30030;

  32.     /** Coefficient of s⁵ in R<sub>C</sub> polynomial. */
  33.     static final double S5 = 32760;

  34.     /** Coefficient of s⁶ in R<sub>C</sub> polynomial. */
  35.     static final double S6 = 61215;

  36.     /** Coefficient of s⁷ in R<sub>C</sub> polynomial. */
  37.     static final double S7 = 90090;

  38.     /** Denominator in R<sub>C</sub> polynomial. */
  39.     static final double DENOMINATOR = 80080;

  40.     /** Simple constructor.
  41.      * @param x first symmetric variable of the integral
  42.      * @param y second symmetric variable of the integral
  43.      */
  44.     RcRealDuplication(final double x, final double y) {
  45.         super(x, y);
  46.     }

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     protected void initialMeanPoint(final double[] va) {
  50.         va[2] =  (va[0] + va[1] * 2) / 3.0;
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     protected double convergenceCriterion(final double r, final double max) {
  55.         return max / FastMath.sqrt(FastMath.sqrt(FastMath.sqrt(r * 3.0)));
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     protected void update(final int m, final double[] vaM, final double[] sqrtM, final  double fourM) {
  60.         final double lambdaA = sqrtM[0] * sqrtM[1] * 2;
  61.         final double lambdaB = vaM[1];
  62.         vaM[0] = MathArrays.linearCombination(0.25, vaM[0], 0.25, lambdaA, 0.25, lambdaB); // xₘ
  63.         vaM[1] = MathArrays.linearCombination(0.25, vaM[1], 0.25, lambdaA, 0.25, lambdaB); // yₘ
  64.         vaM[2] = MathArrays.linearCombination(0.25, vaM[2], 0.25, lambdaA, 0.25, lambdaB); // aₘ
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     protected double evaluate(final double[] va0, final double aM, final  double fourM) {

  69.         // compute the single polynomial independent variable
  70.         final double s = (va0[1] - va0[2]) / (aM * fourM);

  71.         // evaluate integral using equation 2.13 in Carlson[1995]
  72.         final double poly = ((((((S7 * s + S6) * s + S5) * s + S4) * s + S3) * s + S2) * s * s + S0) / DENOMINATOR;
  73.         return poly / FastMath.sqrt(aM);

  74.     }

  75. }