001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.math3.linear;
019
020 import org.apache.commons.math3.FieldElement;
021
022
023 /**
024 * Interface handling decomposition algorithms that can solve A × X = B.
025 * <p>Decomposition algorithms decompose an A matrix has a product of several specific
026 * matrices from which they can solve A × X = B in least squares sense: they find X
027 * such that ||A × X - B|| is minimal.</p>
028 * <p>Some solvers like {@link FieldLUDecomposition} can only find the solution for
029 * square matrices and when the solution is an exact linear solution, i.e. when
030 * ||A × X - B|| is exactly 0. Other solvers can also find solutions
031 * with non-square matrix A and with non-null minimal norm. If an exact linear
032 * solution exists it is also the minimal norm solution.</p>
033 *
034 * @param <T> the type of the field elements
035 * @version $Id: FieldDecompositionSolver.java 1416643 2012-12-03 19:37:14Z tn $
036 * @since 2.0
037 */
038 public interface FieldDecompositionSolver<T extends FieldElement<T>> {
039
040 /** Solve the linear equation A × X = B for matrices A.
041 * <p>The A matrix is implicit, it is provided by the underlying
042 * decomposition algorithm.</p>
043 * @param b right-hand side of the equation A × X = B
044 * @return a vector X that minimizes the two norm of A × X - B
045 * @throws org.apache.commons.math3.exception.DimensionMismatchException
046 * if the matrices dimensions do not match.
047 * @throws SingularMatrixException
048 * if the decomposed matrix is singular.
049 */
050 FieldVector<T> solve(final FieldVector<T> b);
051
052 /** Solve the linear equation A × X = B for matrices A.
053 * <p>The A matrix is implicit, it is provided by the underlying
054 * decomposition algorithm.</p>
055 * @param b right-hand side of the equation A × X = B
056 * @return a matrix X that minimizes the two norm of A × X - B
057 * @throws org.apache.commons.math3.exception.DimensionMismatchException
058 * if the matrices dimensions do not match.
059 * @throws SingularMatrixException
060 * if the decomposed matrix is singular.
061 */
062 FieldMatrix<T> solve(final FieldMatrix<T> b);
063
064 /**
065 * Check if the decomposed matrix is non-singular.
066 * @return true if the decomposed matrix is non-singular
067 */
068 boolean isNonSingular();
069
070 /** Get the inverse (or pseudo-inverse) of the decomposed matrix.
071 * @return inverse matrix
072 * @throws SingularMatrixException
073 * if the decomposed matrix is singular.
074 */
075 FieldMatrix<T> getInverse();
076 }