View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) 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 ASF 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  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  
23  package org.hipparchus.linear;
24  
25  import org.hipparchus.FieldElement;
26  
27  
28  /**
29   * Interface handling decomposition algorithms that can solve A × X = B.
30   * <p>
31   * Decomposition algorithms decompose an A matrix has a product of several specific
32   * matrices from which they can solve A &times; X = B in least squares sense: they find X
33   * such that ||A &times; X - B|| is minimal.
34   * <p>
35   * Some solvers like {@link FieldLUDecomposition} can only find the solution for
36   * square matrices and when the solution is an exact linear solution, i.e. when
37   * ||A &times; X - B|| is exactly 0. Other solvers can also find solutions
38   * with non-square matrix A and with non-null minimal norm. If an exact linear
39   * solution exists it is also the minimal norm solution.
40   *
41   * @param <T> the type of the field elements
42   */
43  public interface FieldDecompositionSolver<T extends FieldElement<T>> {
44  
45      /** Solve the linear equation A &times; X = B for matrices A.
46       * <p>The A matrix is implicit, it is provided by the underlying
47       * decomposition algorithm.</p>
48       * @param b right-hand side of the equation A &times; X = B
49       * @return a vector X that minimizes the two norm of A &times; X - B
50       * @throws org.hipparchus.exception.MathIllegalArgumentException
51       * if the matrices dimensions do not match or the decomposed matrix
52       * is singular.
53       */
54      FieldVector<T> solve(FieldVector<T> b);
55  
56      /** Solve the linear equation A &times; X = B for matrices A.
57       * <p>The A matrix is implicit, it is provided by the underlying
58       * decomposition algorithm.</p>
59       * @param b right-hand side of the equation A &times; X = B
60       * @return a matrix X that minimizes the two norm of A &times; X - B
61       * @throws org.hipparchus.exception.MathIllegalArgumentException
62       * if the matrices dimensions do not match or the decomposed matrix
63       * is singular.
64       */
65      FieldMatrix<T> solve(FieldMatrix<T> b);
66  
67      /**
68       * Check if the decomposed matrix is non-singular.
69       * @return true if the decomposed matrix is non-singular
70       */
71      boolean isNonSingular();
72  
73      /** Get the inverse (or pseudo-inverse) of the decomposed matrix.
74       * @return inverse matrix
75       * @throws org.hipparchus.exception.MathIllegalArgumentException
76       * if the decomposed matrix is singular.
77       */
78      FieldMatrix<T> getInverse();
79  
80      /**
81       * Returns the number of rows in the matrix.
82       *
83       * @return rowDimension
84       * @since 2.0
85       */
86      int getRowDimension();
87  
88      /**
89       * Returns the number of columns in the matrix.
90       *
91       * @return columnDimension
92       * @since 2.0
93       */
94      int getColumnDimension();
95  
96  }