HansenUtilities.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS 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.  *   http://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.orekit.propagation.semianalytical.dsst.utilities.hansen;

  18. import org.hipparchus.analysis.polynomials.PolynomialFunction;

  19. /**
  20.  * Utilities class.
  21.  *
  22.  * @author Lucian Barbulescu
  23.  */
  24. public class HansenUtilities {

  25.     /** 1 represented as a polynomial. */
  26.     public static final PolynomialFunction ONE = new PolynomialFunction(new double[] {
  27.         1
  28.     });

  29.     /** 0 represented as a polynomial. */
  30.     public static final PolynomialFunction ZERO = new PolynomialFunction(new double[] {
  31.         0
  32.     });

  33.     /** Private constructor as class is a utility.
  34.      */
  35.     private HansenUtilities() {
  36.     }

  37.     /**
  38.      * Build the identity matrix of order 2.
  39.      *
  40.      * <pre>
  41.      *       / 1   0 \
  42.      *  I₂ = |       |
  43.      *       \ 0   1 /
  44.      * </pre>
  45.      *
  46.      * @return the identity matrix of order 2
  47.      */
  48.     public static PolynomialFunctionMatrix buildIdentityMatrix2() {
  49.         final PolynomialFunctionMatrix matrix = new PolynomialFunctionMatrix(2);
  50.         matrix.setMatrix(new PolynomialFunction[][] {
  51.             {
  52.                 ONE,  ZERO
  53.             },
  54.             {
  55.                 ZERO, ONE
  56.             }
  57.         });
  58.         return matrix;
  59.     }

  60.     /**
  61.      * Build the empty matrix of order 2.
  62.      *
  63.      * <pre>
  64.      *       / 0   0 \
  65.      *  E₂ = |       |
  66.      *       \ 0   0 /
  67.      * </pre>
  68.      *
  69.      * @return the identity matrix of order 2
  70.      */
  71.     public static PolynomialFunctionMatrix buildZeroMatrix2() {
  72.         final PolynomialFunctionMatrix matrix = new PolynomialFunctionMatrix(2);
  73.         matrix.setMatrix(new PolynomialFunction[][] {
  74.             {
  75.                 ZERO, ZERO
  76.             },
  77.             {
  78.                 ZERO, ZERO
  79.             }
  80.         });
  81.         return matrix;
  82.     }


  83.     /**
  84.      * Build the identity matrix of order 4.
  85.      *
  86.      * <pre>
  87.      *       / 1  0  0  0 \
  88.      *       |            |
  89.      *       | 0  1  0  0 |
  90.      *  I₄ = |            |
  91.      *       | 0  0  1  0 |
  92.      *       |            |
  93.      *       \ 0  0  0  1 /
  94.      * </pre>
  95.      *
  96.      * @return the identity matrix of order 4
  97.      */
  98.     public static PolynomialFunctionMatrix buildIdentityMatrix4() {
  99.         final PolynomialFunctionMatrix matrix = new PolynomialFunctionMatrix(4);
  100.         matrix.setMatrix(new PolynomialFunction[][] {
  101.             {
  102.                 ONE,  ZERO, ZERO, ZERO
  103.             },
  104.             {
  105.                 ZERO, ONE,  ZERO, ZERO
  106.             },
  107.             {
  108.                 ZERO, ZERO, ONE,  ZERO
  109.             },
  110.             {
  111.                 ZERO, ZERO, ZERO, ONE
  112.             }
  113.         });
  114.         return matrix;
  115.     }

  116.     /**
  117.      * Build the empty matrix of order 4.
  118.      *
  119.      * <pre>
  120.      *       / 0  0  0  0 \
  121.      *       |            |
  122.      *       | 0  0  0  0 |
  123.      *  E₄ = |            |
  124.      *       | 0  0  0  0 |
  125.      *       |            |
  126.      *       \ 0  0  0  0 /
  127.      * </pre>
  128.      *
  129.      * @return the identity matrix of order 4
  130.      */
  131.     public static PolynomialFunctionMatrix buildZeroMatrix4() {
  132.         final PolynomialFunctionMatrix matrix = new PolynomialFunctionMatrix(4);
  133.         matrix.setMatrix(new PolynomialFunction[][] {
  134.             {
  135.                 ZERO, ZERO, ZERO, ZERO
  136.             },
  137.             {
  138.                 ZERO, ZERO, ZERO, ZERO
  139.             },
  140.             {
  141.                 ZERO, ZERO, ZERO, ZERO
  142.             },
  143.             {
  144.                 ZERO, ZERO, ZERO, ZERO
  145.             }
  146.         } );
  147.         return matrix;
  148.     }

  149.     /**
  150.      * Compute polynomial coefficient a.
  151.      *
  152.      *  <p>
  153.      *  It is used to generate the coefficient for K₀<sup>-n, s</sup> when computing K₀<sup>-n-1, s</sup>
  154.      *  and the coefficient for dK₀<sup>-n, s</sup> / de² when computing dK₀<sup>-n-1, s</sup> / de²
  155.      *  </p>
  156.      *
  157.      *  <p>
  158.      *  See Danielson 2.7.3-(6) and Collins 4-242 and 4-245
  159.      *  </p>
  160.      *
  161.      * @param s the s coefficient
  162.      * @param mnm1 -n-1 value
  163.      * @return the polynomial
  164.      */
  165.     private static PolynomialFunction aZonal(final int s, final int mnm1) {
  166.         // from recurrence Collins 4-242
  167.         final double d1 = (mnm1 + 2) * (2 * mnm1 + 5);
  168.         final double d2 = (mnm1 + 2 - s) * (mnm1 + 2 + s);
  169.         return new PolynomialFunction(new double[] {
  170.             0.0, 0.0, d1 / d2
  171.         });
  172.     }

  173.     /**
  174.      * Compute polynomial coefficient b.
  175.      *
  176.      *  <p>
  177.      *  It is used to generate the coefficient for K₀<sup>-n+1, s</sup> when computing K₀<sup>-n-1, s</sup>
  178.      *  and the coefficient for dK₀<sup>-n+1, s</sup> / de² when computing dK₀<sup>-n-1, s</sup> / de²
  179.      *  </p>
  180.      *
  181.      *  <p>
  182.      *  See Danielson 2.7.3-(6) and Collins 4-242 and 4-245
  183.      *  </p>
  184.      *
  185.      * @param s the s coefficient
  186.      * @param mnm1 -n-1 value
  187.      * @return the polynomial
  188.      */
  189.     private static PolynomialFunction bZonal(final int s, final int mnm1) {
  190.         // from recurence Collins 4-242
  191.         final double d1 = (mnm1 + 2) * (mnm1 + 3);
  192.         final double d2 = (mnm1 + 2 - s) * (mnm1 + 2 + s);
  193.         return new PolynomialFunction(new double[] {
  194.             0.0, 0.0, -d1 / d2
  195.         });
  196.     }

  197.     /**
  198.      * Generate the polynomials needed in the linear transformation.
  199.      *
  200.      * @param n0         the index of the initial condition, Petre's paper
  201.      * @param nMin       rhe minimum value for the order
  202.      * @param offset     offset used to identify the polynomial that corresponds
  203.      *                   to a negative value of n in the internal array that
  204.      *                   starts at 0
  205.      * @param slice      number of coefficients that will be computed with a set
  206.      *                   of roots
  207.      * @param s          the s coefficient
  208.      * @param mpvec      array to store the first vector of polynomials
  209.      *                   associated to Hansen coefficients and derivatives.
  210.      * @param mpvecDeriv array to store the second vector of polynomials
  211.      *                   associated only to derivatives.
  212.      * <p>
  213.      * See Petre's paper
  214.      * </p>
  215.      */
  216.     public static void generateZonalPolynomials(final int n0, final int nMin,
  217.                                                 final int offset, final int slice,
  218.                                                 final int s,
  219.                                                 final PolynomialFunction[][] mpvec,
  220.                                                 final PolynomialFunction[][] mpvecDeriv) {

  221.         int sliceCounter = 0;
  222.         int index;

  223.         // Initialisation of matrix for linear transformmations
  224.         // The final configuration of these matrix are obtained by composition
  225.         // of linear transformations
  226.         PolynomialFunctionMatrix A = HansenUtilities.buildIdentityMatrix2();
  227.         PolynomialFunctionMatrix D = HansenUtilities.buildZeroMatrix2();
  228.         PolynomialFunctionMatrix E = HansenUtilities.buildIdentityMatrix2();

  229.         // generation of polynomials associated to Hansen coefficients and to
  230.         // their derivatives
  231.         final PolynomialFunctionMatrix a = HansenUtilities.buildZeroMatrix2();
  232.         a.setElem(0, 1, HansenUtilities.ONE);

  233.         //The B matrix is constant.
  234.         final PolynomialFunctionMatrix B = HansenUtilities.buildZeroMatrix2();
  235.         // from Collins 4-245 and Petre's paper
  236.         B.setElem(1, 1, new PolynomialFunction(new double[] {
  237.             2.0
  238.         }));

  239.         for (int i = n0 - 1; i > nMin - 1; i--) {
  240.             index = i + offset;
  241.             // Matrix of the current linear transformation
  242.             // Petre's paper
  243.             a.setMatrixLine(1, new PolynomialFunction[] {
  244.                 bZonal(s, i), aZonal(s, i)
  245.             });
  246.             // composition of linear transformations
  247.             // see Petre's paper
  248.             A = A.multiply(a);
  249.             // store the polynomials for Hansen coefficients
  250.             mpvec[index] = A.getMatrixLine(1);

  251.             D = D.multiply(a);
  252.             E = E.multiply(a);
  253.             D = D.add(E.multiply(B));

  254.             // store the polynomials for Hansen coefficients from the expressions
  255.             // of derivatives
  256.             mpvecDeriv[index] = D.getMatrixLine(1);

  257.             if (++sliceCounter % slice == 0) {
  258.                 // Re-Initialisation of matrix for linear transformmations
  259.                 // The final configuration of these matrix are obtained by composition
  260.                 // of linear transformations
  261.                 A = HansenUtilities.buildIdentityMatrix2();
  262.                 D = HansenUtilities.buildZeroMatrix2();
  263.                 E = HansenUtilities.buildIdentityMatrix2();
  264.             }

  265.         }
  266.     }

  267.     /**
  268.      * Compute polynomial coefficient a.
  269.      *
  270.      *  <p>
  271.      *  It is used to generate the coefficient for K<sub>j</sub><sup>-n, s</sup> when computing K<sub>j</sub><sup>-n-1, s</sup>
  272.      *  and the coefficient for dK<sub>j</sub><sup>-n, s</sup> / de² when computing dK<sub>j</sub><sup>-n-1, s</sup> / de²
  273.      *  </p>
  274.      *
  275.      *  <p>
  276.      *  See Danielson 2.7.3-(9) and Collins 4-236 and 4-240
  277.      *  </p>
  278.      *
  279.      * @param s the s coefficient
  280.      * @param mnm1 -n-1
  281.      * @return the polynomial
  282.      */
  283.     private static PolynomialFunction aTesseral(final int s, final int mnm1) {
  284.         // Collins 4-236, Danielson 2.7.3-(9)
  285.         final double r1 = (mnm1 + 2.) * (2. * mnm1 + 5.);
  286.         final double r2 = (2. + mnm1 + s) * (2. + mnm1 - s);
  287.         return new PolynomialFunction(new double[] {
  288.             0.0, 0.0, r1 / r2
  289.         });
  290.     }

  291.     /**
  292.      * Compute polynomial coefficient b.
  293.      *
  294.      *  <p>
  295.      *  It is used to generate the coefficient for K<sub>j</sub><sup>-n+1, s</sup> when computing K<sub>j</sub><sup>-n-1, s</sup>
  296.      *  and the coefficient for dK<sub>j</sub><sup>-n+1, s</sup> / de² when computing dK<sub>j</sub><sup>-n-1, s</sup> / de²
  297.      *  </p>
  298.      *
  299.      *  <p>
  300.      *  See Danielson 2.7.3-(9) and Collins 4-236 and 4-240
  301.      *  </p>
  302.      *
  303.      * @param j the j coefficient
  304.      * @param s the s coefficient
  305.      * @param mnm1 -n-1
  306.      * @return the polynomial
  307.      */
  308.     private static PolynomialFunction bTesseral(final int j, final int s, final int mnm1) {
  309.         // Collins 4-236, Danielson 2.7.3-(9)
  310.         final double r2 = (2. + mnm1 + s) * (2. + mnm1 - s);
  311.         final double d1 = (mnm1 + 3.) * 2. * j * s / (r2 * (mnm1 + 4.));
  312.         final double d2 = (mnm1 + 3.) * (mnm1 + 2.) / r2;
  313.         return new PolynomialFunction(new double[] {
  314.             0.0, -d1, -d2
  315.         });
  316.     }

  317.     /**
  318.      * Compute polynomial coefficient c.
  319.      *
  320.      *  <p>
  321.      *  It is used to generate the coefficient for K<sub>j</sub><sup>-n+3, s</sup> when computing K<sub>j</sub><sup>-n-1, s</sup>
  322.      *  and the coefficient for dK<sub>j</sub><sup>-n+3, s</sup> / de² when computing dK<sub>j</sub><sup>-n-1, s</sup> / de²
  323.      *  </p>
  324.      *
  325.      *  <p>
  326.      *  See Danielson 2.7.3-(9) and Collins 4-236 and 4-240
  327.      *  </p>
  328.      *
  329.      * @param j the j coefficient
  330.      * @param s the s coefficient
  331.      * @param mnm1 -n-1
  332.      * @return the polynomial
  333.      */
  334.     private static PolynomialFunction cTesseral(final int j, final int s, final int mnm1) {
  335.         // Collins 4-236, Danielson 2.7.3-(9)
  336.         final double r1 = j * j * (mnm1 + 2.);
  337.         final double r2 = (mnm1 + 4.) * (2. + mnm1 + s) * (2. + mnm1 - s);

  338.         return new PolynomialFunction(new double[] {
  339.             0.0, 0.0, r1 / r2
  340.         });
  341.     }

  342.     /**
  343.      * Compute polynomial coefficient d.
  344.      * <p>
  345.      * It is used to generate the coefficient for K<sub>j</sub><sup>-n-1,
  346.      * s</sup> / dχ when computing dK<sub>j</sub><sup>-n-1, s</sup> / de²
  347.      * </p>
  348.      * <p>
  349.      * See Danielson 2.7.3-(9) and Collins 4-236 and 4-240
  350.      * </p>
  351.      *
  352.      * @return the polynomial
  353.      */
  354.     private static PolynomialFunction dTesseral() {
  355.         // Collins 4-236, Danielson 2.7.3-(9)
  356.         return new PolynomialFunction(new double[] {
  357.             0.0, 0.0, 1.0
  358.         });
  359.     }

  360.     /**
  361.      * Compute polynomial coefficient f.
  362.      *
  363.      *  <p>
  364.      *  It is used to generate the coefficient for K<sub>j</sub><sup>-n+1, s</sup> / dχ when computing dK<sub>j</sub><sup>-n-1, s</sup> / de²
  365.      *  </p>
  366.      *
  367.      *  <p>
  368.      *  See Danielson 2.7.3-(9) and Collins 4-236 and 4-240
  369.      *  </p>
  370.      *
  371.      * @param j the j coefficient
  372.      * @param s the s coefficient
  373.      * @param n index
  374.      * @return the polynomial
  375.      */
  376.     private static PolynomialFunction fTesseral(final int j, final int s, final int n) {
  377.         // Collins 4-236, Danielson 2.7.3-(9)
  378.         final double r1 = (n + 3.0) * j * s;
  379.         final double r2 = (n + 4.0) * (2.0 + n + s) * (2.0 + n - s);
  380.         return new PolynomialFunction(new double[] {
  381.             0.0, 0.0, 0.0, r1 / r2
  382.         });
  383.     }

  384.     /**
  385.      * Generate the polynomials needed in the linear transformation.
  386.      *
  387.      * @param n0         the index of the initial condition, Petre's paper
  388.      * @param nMin       rhe minimum value for the order
  389.      * @param offset     offset used to identify the polynomial that corresponds
  390.      *                   to a negative value of n in the internal array that
  391.      *                   starts at 0
  392.      * @param slice      number of coefficients that will be computed with a set
  393.      *                   of roots
  394.      * @param j          the j coefficient
  395.      * @param s          the s coefficient
  396.      * @param mpvec      array to store the first vector of polynomials
  397.      *                   associated to Hansen coefficients and derivatives.
  398.      * @param mpvecDeriv array to store the second vector of polynomials
  399.      *                   associated only to derivatives.
  400.      */
  401.     public static void generateTesseralPolynomials(final int n0, final int nMin,
  402.                                                    final int offset, final int slice,
  403.                                                    final int j, final int s,
  404.                                                    final PolynomialFunction[][] mpvec,
  405.                                                    final PolynomialFunction[][] mpvecDeriv) {


  406.         // Initialization of the matrices for linear transformations
  407.         // The final configuration of these matrices are obtained by composition
  408.         // of linear transformations

  409.         // The matrix of polynomials associated to Hansen coefficients, Petre's
  410.         // paper
  411.         PolynomialFunctionMatrix A = HansenUtilities.buildIdentityMatrix4();

  412.         // The matrix of polynomials associated to derivatives, Petre's paper
  413.         final PolynomialFunctionMatrix B = HansenUtilities.buildZeroMatrix4();
  414.         PolynomialFunctionMatrix D = HansenUtilities.buildZeroMatrix4();
  415.         final PolynomialFunctionMatrix a = HansenUtilities.buildZeroMatrix4();

  416.         // The matrix of the current linear transformation
  417.         a.setMatrixLine(0, new PolynomialFunction[] {
  418.             HansenUtilities.ZERO, HansenUtilities.ONE, HansenUtilities.ZERO, HansenUtilities.ZERO
  419.         });
  420.         a.setMatrixLine(1, new PolynomialFunction[] {
  421.             HansenUtilities.ZERO, HansenUtilities.ZERO, HansenUtilities.ONE, HansenUtilities.ZERO
  422.         });
  423.         a.setMatrixLine(2, new PolynomialFunction[] {
  424.             HansenUtilities.ZERO, HansenUtilities.ZERO, HansenUtilities.ZERO, HansenUtilities.ONE
  425.         });
  426.         // The generation process
  427.         int index;
  428.         int sliceCounter = 0;
  429.         for (int i = n0 - 1; i > nMin - 1; i--) {
  430.             index = i + offset;
  431.             // The matrix of the current linear transformation is updated
  432.             // Petre's paper
  433.             a.setMatrixLine(3, new PolynomialFunction[] {
  434.                 cTesseral(j, s, i), HansenUtilities.ZERO, bTesseral(j, s, i), aTesseral(s, i)
  435.             });

  436.             // composition of the linear transformations to calculate
  437.             // the polynomials associated to Hansen coefficients
  438.             // Petre's paper
  439.             A = A.multiply(a);
  440.             // store the polynomials for Hansen coefficients
  441.             mpvec[index] = A.getMatrixLine(3);
  442.             // composition of the linear transformations to calculate
  443.             // the polynomials associated to derivatives
  444.             // Petre's paper
  445.             D = D.multiply(a);

  446.             //Update the B matrix
  447.             B.setMatrixLine(3, new PolynomialFunction[] {
  448.                 HansenUtilities.ZERO, fTesseral(j, s, i),
  449.                 HansenUtilities.ZERO, dTesseral()
  450.             });
  451.             D = D.add(A.multiply(B));

  452.             // store the polynomials for Hansen coefficients from the
  453.             // expressions of derivatives
  454.             mpvecDeriv[index] = D.getMatrixLine(3);

  455.             if (++sliceCounter % slice == 0) {
  456.                 // Re-Initialisation of matrix for linear transformmations
  457.                 // The final configuration of these matrix are obtained by composition
  458.                 // of linear transformations
  459.                 A = HansenUtilities.buildIdentityMatrix4();
  460.                 D = HansenUtilities.buildZeroMatrix4();
  461.             }
  462.         }
  463.     }

  464.     /**
  465.      * Compute polynomial coefficient a.
  466.      *
  467.      *  <p>
  468.      *  It is used to generate the coefficient for K₀<sup>n-1, s</sup> when computing K₀<sup>n, s</sup>
  469.      *  and the coefficient for dK₀<sup>n-1, s</sup> / d&Chi; when computing dK₀<sup>n, s</sup> / d&Chi;
  470.      *  </p>
  471.      *
  472.      *  <p>
  473.      *  See Danielson 2.7.3-(7c) and Collins 4-254 and 4-257
  474.      *  </p>
  475.      *
  476.      * @param n n value
  477.      * @return the polynomial
  478.      */
  479.     private static PolynomialFunction aThirdBody(final int n) {
  480.         // from recurrence Danielson 2.7.3-(7c), Collins 4-254
  481.         final double r1 = 2 * n + 1;
  482.         final double r2 = n + 1;

  483.         return new PolynomialFunction(new double[] {
  484.             r1 / r2
  485.         });
  486.     }

  487.     /**
  488.      * Compute polynomial coefficient b.
  489.      *
  490.      *  <p>
  491.      *  It is used to generate the coefficient for K₀<sup>n-2, s</sup> when computing K₀<sup>n, s</sup>
  492.      *  and the coefficient for dK₀<sup>n-2, s</sup> / d&Chi; when computing dK₀<sup>n, s</sup> / d&Chi;
  493.      *  </p>
  494.      *
  495.      *  <p>
  496.      *  See Danielson 2.7.3-(7c) and Collins 4-254 and 4-257
  497.      *  </p>
  498.      *
  499.      * @param s          the s coefficient
  500.      * @param n n value
  501.      * @return the polynomial
  502.      */
  503.     private static PolynomialFunction bThirdBody(final int s, final int n) {
  504.         // from recurrence Danielson 2.7.3-(7c), Collins 4-254
  505.         final double r1 = (n + s) * (n - s);
  506.         final double r2 = n * (n + 1);

  507.         return new PolynomialFunction(new double[] {
  508.             0.0, 0.0, -r1 / r2
  509.         });
  510.     }

  511.     /**
  512.      * Compute polynomial coefficient d.
  513.      *
  514.      *  <p>
  515.      *  It is used to generate the coefficient for K₀<sup>n-2, s</sup> when computing dK₀<sup>n, s</sup> / d&Chi;
  516.      *  </p>
  517.      *
  518.      *  <p>
  519.      *  See Danielson 2.7.3-(7c) and Collins 4-254 and 4-257
  520.      *  </p>
  521.      *
  522.      * @param s the s coefficient
  523.      * @param n n value
  524.      * @return the polynomial
  525.      */
  526.     private static PolynomialFunction dThirdBody(final int s, final int n) {
  527.         // from Danielson 3.2-(3b)
  528.         final double r1 = 2 * (n + s) * (n - s);
  529.         final double r2 = n * (n + 1);

  530.         return new PolynomialFunction(new double[] {
  531.             0.0, 0.0, 0.0, r1 / r2
  532.         });
  533.     }

  534.     /**
  535.      * Generate the polynomials needed in the linear transformation.
  536.      *
  537.      * @param n0 the index of the initial condition, Petre's paper
  538.      * @param nMax the maximum order of n indexes
  539.      * @param slice number of coefficients that will be computed with a set of roots
  540.      * @param s the s coefficient
  541.      * @param mpvec      array to store the first vector of polynomials
  542.      *                   associated to Hansen coefficients and derivatives.
  543.      * @param mpvecDeriv array to store the second vector of polynomials
  544.      *                   associated only to derivatives.
  545.      * <p>
  546.      * See Petre's paper
  547.      * </p>
  548.      */
  549.     public static void generateThirdBodyPolynomials(final int n0, final int nMax,
  550.                                                     final int slice,
  551.                                                     final int s,
  552.                                                     final PolynomialFunction[][] mpvec,
  553.                                                     final PolynomialFunction[][] mpvecDeriv) {

  554.         int sliceCounter = 0;

  555.         // Initialization of the matrices for linear transformations
  556.         // The final configuration of these matrices are obtained by composition
  557.         // of linear transformations

  558.         // the matrix A for the polynomials associated
  559.         // to Hansen coefficients, Petre's pater
  560.         PolynomialFunctionMatrix A = HansenUtilities.buildIdentityMatrix2();

  561.         // the matrix D for the polynomials associated
  562.         // to derivatives, Petre's paper
  563.         final PolynomialFunctionMatrix B = HansenUtilities.buildZeroMatrix2();
  564.         PolynomialFunctionMatrix D = HansenUtilities.buildZeroMatrix2();
  565.         PolynomialFunctionMatrix E = HansenUtilities.buildIdentityMatrix2();

  566.         // The matrix that contains the coefficients at each step
  567.         final PolynomialFunctionMatrix a = HansenUtilities.buildZeroMatrix2();
  568.         a.setElem(0, 1, HansenUtilities.ONE);

  569.         // The generation process
  570.         for (int i = n0 + 2; i <= nMax; i++) {
  571.             // Collins 4-254 or Danielson 2.7.3-(7)
  572.             // Petre's paper
  573.             // The matrix of the current linear transformation is actualized
  574.             a.setMatrixLine(1, new PolynomialFunction[] {
  575.                 bThirdBody(s, i), aThirdBody(i)
  576.             });

  577.             // composition of the linear transformations to calculate
  578.             // the polynomials associated to Hansen coefficients
  579.             A = A.multiply(a);
  580.             // store the polynomials associated to Hansen coefficients
  581.             mpvec[i] = A.getMatrixLine(1);
  582.             // composition of the linear transformations to calculate
  583.             // the polynomials associated to derivatives
  584.             // Danielson 3.2-(3b) and Petre's paper
  585.             D = D.multiply(a);
  586.             if (sliceCounter % slice != 0) {
  587.                 a.setMatrixLine(1, new PolynomialFunction[] {
  588.                     bThirdBody(s, i - 1), aThirdBody(i - 1)
  589.                 });
  590.                 E = E.multiply(a);
  591.             }

  592.             B.setElem(1, 0, dThirdBody(s, i));
  593.             // F = E.prod(B);
  594.             D = D.add(E.multiply(B));
  595.             // store the polynomials associated to the derivatives
  596.             mpvecDeriv[i] = D.getMatrixLine(1);

  597.             if (++sliceCounter % slice == 0) {
  598.                 // Re-Initialization of the matrices for linear transformations
  599.                 // The final configuration of these matrices are obtained by composition
  600.                 // of linear transformations
  601.                 A = HansenUtilities.buildIdentityMatrix2();
  602.                 D = HansenUtilities.buildZeroMatrix2();
  603.                 E = HansenUtilities.buildIdentityMatrix2();
  604.             }
  605.         }
  606.     }

  607. }