RcFieldDuplication.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.CalculusFieldElement;
  19. import org.hipparchus.complex.Complex;
  20. import org.hipparchus.complex.FieldComplex;
  21. import org.hipparchus.util.FastMath;

  22. /** Duplication algorithm for Carlson R<sub>C</sub> elliptic integral.
  23.  * @param <T> type of the field elements (really {@link Complex} or {@link FieldComplex})
  24.  * @since 2.0
  25.  */
  26. class RcFieldDuplication<T extends CalculusFieldElement<T>> extends FieldDuplication<T> {

  27.     /** Simple constructor.
  28.      * @param x first symmetric variable of the integral
  29.      * @param y second symmetric variable of the integral
  30.      */
  31.     RcFieldDuplication(final T x, final T y) {
  32.         super(x, y);
  33.     }

  34.     /** {@inheritDoc} */
  35.     @Override
  36.     protected void initialMeanPoint(final T[] va) {
  37.         va[2] = va[0].add(va[1].multiply(2)).divide(3.0);
  38.     }

  39.     /** {@inheritDoc} */
  40.     @Override
  41.     protected T convergenceCriterion(final T r, final T max) {
  42.         return max.divide(FastMath.sqrt(FastMath.sqrt(FastMath.sqrt(r.multiply(3.0)))));
  43.     }

  44.     /** {@inheritDoc} */
  45.     @Override
  46.     protected void update(final int m, final T[] vaM, final T[] sqrtM, final  double fourM) {
  47.         final T lambdaA = sqrtM[0].multiply(sqrtM[1]).multiply(2);
  48.         final T lambdaB = vaM[1];
  49.         vaM[0] = vaM[0].linearCombination(0.25, vaM[0], 0.25, lambdaA, 0.25, lambdaB); // xₘ
  50.         vaM[1] = vaM[1].linearCombination(0.25, vaM[1], 0.25, lambdaA, 0.25, lambdaB); // yₘ
  51.         vaM[2] = vaM[2].linearCombination(0.25, vaM[2], 0.25, lambdaA, 0.25, lambdaB); // aₘ
  52.     }

  53.     /** {@inheritDoc} */
  54.     @Override
  55.     protected T evaluate(final T[] va0, final T aM, final  double fourM) {

  56.         // compute the single polynomial independent variable
  57.         final T s = va0[1].subtract(va0[2]).divide(aM.multiply(fourM));

  58.         // evaluate integral using equation 2.13 in Carlson[1995]
  59.         final T poly = s.multiply(RcRealDuplication.S7).
  60.                        add(RcRealDuplication.S6).multiply(s).
  61.                        add(RcRealDuplication.S5).multiply(s).
  62.                        add(RcRealDuplication.S4).multiply(s).
  63.                        add(RcRealDuplication.S3).multiply(s).
  64.                        add(RcRealDuplication.S2).multiply(s).
  65.                        multiply(s).
  66.                        add(RcRealDuplication.S0).
  67.                        divide(RcRealDuplication.DENOMINATOR);
  68.         return poly.divide(FastMath.sqrt(aM));

  69.     }

  70. }