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    *      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  
18  package org.apache.commons.math3.linear;
19  
20  
21  
22  /**
23   * Interface handling decomposition algorithms that can solve A × X = B.
24   * <p>Decomposition algorithms decompose an A matrix has a product of several specific
25   * matrices from which they can solve A &times; X = B in least squares sense: they find X
26   * such that ||A &times; X - B|| is minimal.</p>
27   * <p>Some solvers like {@link LUDecomposition} can only find the solution for
28   * square matrices and when the solution is an exact linear solution, i.e. when
29   * ||A &times; X - B|| is exactly 0. Other solvers can also find solutions
30   * with non-square matrix A and with non-null minimal norm. If an exact linear
31   * solution exists it is also the minimal norm solution.</p>
32   *
33   * @version $Id: DecompositionSolver.java 1416643 2012-12-03 19:37:14Z tn $
34   * @since 2.0
35   */
36  public interface DecompositionSolver {
37  
38      /** Solve the linear equation A &times; X = B for matrices A.
39       * <p>The A matrix is implicit, it is provided by the underlying
40       * decomposition algorithm.</p>
41       * @param b right-hand side of the equation A &times; X = B
42       * @return a vector X that minimizes the two norm of A &times; X - B
43       * @throws org.apache.commons.math3.exception.DimensionMismatchException
44       * if the matrices dimensions do not match.
45       * @throws SingularMatrixException
46       * if the decomposed matrix is singular.
47       */
48      RealVector solve(final RealVector b);
49  
50      /** Solve the linear equation A &times; X = B for matrices A.
51       * <p>The A matrix is implicit, it is provided by the underlying
52       * decomposition algorithm.</p>
53       * @param b right-hand side of the equation A &times; X = B
54       * @return a matrix X that minimizes the two norm of A &times; X - B
55       * @throws org.apache.commons.math3.exception.DimensionMismatchException
56       * if the matrices dimensions do not match.
57       * @throws SingularMatrixException
58       * if the decomposed matrix is singular.
59       */
60      RealMatrix solve(final RealMatrix b);
61  
62      /**
63       * Check if the decomposed matrix is non-singular.
64       * @return true if the decomposed matrix is non-singular.
65       */
66      boolean isNonSingular();
67  
68      /** Get the inverse (or pseudo-inverse) of the decomposed matrix.
69       * @return inverse matrix
70       * @throws SingularMatrixException
71       * if the decomposed matrix is singular.
72       */
73      RealMatrix getInverse();
74  }