PolynomialFunctionMatrix.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.  * A quadratic matrix of
  21.  * {@link org.hipparchus.analysis.polynomials.PolynomialFunction}.
  22.  *
  23.  * @author Petre Bazavan
  24.  * @author Lucian Barbulescu
  25.  */
  26. public class PolynomialFunctionMatrix {

  27.     /** The order of the matrix. */
  28.     private int order;
  29.     /** The elements of the matrix. */
  30.     private PolynomialFunction[][] elements;

  31.     /**
  32.      * Create a matrix.
  33.      *
  34.      * <p>
  35.      * All elements are null
  36.      *
  37.      * @param order
  38.      *            the order of the matrix
  39.      */
  40.     PolynomialFunctionMatrix(final int order) {
  41.         this.order = order;
  42.         this.elements = new PolynomialFunction[order][order];
  43.     }

  44.     /**
  45.      * Set an element of the matrix.
  46.      *
  47.      * @param line
  48.      *            the line
  49.      * @param column
  50.      *            the column
  51.      * @param value
  52.      *            the value
  53.      */
  54.     public void setElem(final int line, final int column, final PolynomialFunction value) {
  55.         elements[line][column] = value;
  56.     }

  57.     /**
  58.      * Get the value of an element.
  59.      *
  60.      * @param line
  61.      *            the line
  62.      * @param column
  63.      *            the column
  64.      * @return the value
  65.      */
  66.     public PolynomialFunction getElem(final int line, final int column) {
  67.         return elements[line][column];
  68.     }

  69.     /**
  70.      * Multiply the argument matrix with the current matrix.
  71.      *
  72.      * @param matrix
  73.      *            the argument matrix
  74.      * @return the result of the multiplication
  75.      */
  76.     public PolynomialFunctionMatrix multiply(final PolynomialFunctionMatrix matrix) {
  77.         final PolynomialFunctionMatrix result = new PolynomialFunctionMatrix(order);
  78.         for (int i = 0; i < order; i++) {
  79.             for (int j = 0; j < order; j++) {
  80.                 PolynomialFunction cc = HansenUtilities.ZERO;
  81.                 for (int k = 0; k < order; k++) {
  82.                     cc = cc.add(matrix.getElem(i, k).multiply(elements[k][j]));
  83.                 }
  84.                 result.setElem(i, j, cc);
  85.             }
  86.         }
  87.         return result;
  88.     }

  89.     /**
  90.      * Set values for all elements.
  91.      *
  92.      * @param polynomials
  93.      *            the values that will be used for the matrix
  94.      */
  95.     public void setMatrix(final PolynomialFunction[][] polynomials) {
  96.         elements = polynomials.clone();
  97.     }

  98.     /**
  99.      * Set the value of a line of the matrix.
  100.      *
  101.      * @param line
  102.      *            the line number
  103.      * @param polynomials
  104.      *            the values to set
  105.      */
  106.     public void setMatrixLine(final int line, final PolynomialFunction[] polynomials) {
  107.         elements[line] = polynomials;
  108.     }

  109.     /**
  110.      * Get a line of the matrix.
  111.      *
  112.      * @param line
  113.      *            the line number
  114.      * @return the line of the matrix as a vector
  115.      */
  116.     public PolynomialFunction[] getMatrixLine(final int line) {
  117.         return elements[line].clone();
  118.     }

  119.     /**
  120.      * Add the argument matrix with the current matrix.
  121.      *
  122.      * @param matrix
  123.      *            the argument matrix
  124.      * @return the result of the addition
  125.      */
  126.     public PolynomialFunctionMatrix add(final PolynomialFunctionMatrix matrix) {
  127.         final PolynomialFunctionMatrix c = new PolynomialFunctionMatrix(order);
  128.         for (int i = 0; i < order; i++) {
  129.             for (int j = 0; j < order; j++) {
  130.                 c.setElem(i, j, elements[i][j].add(matrix.getElem(i, j)));
  131.             }
  132.         }
  133.         return c;
  134.     }
  135. }