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    
021    
022    /**
023     * Interface handling decomposition algorithms that can solve A × X = B.
024     * <p>Decomposition algorithms decompose an A matrix has a product of several specific
025     * matrices from which they can solve A &times; X = B in least squares sense: they find X
026     * such that ||A &times; X - B|| is minimal.</p>
027     * <p>Some solvers like {@link LUDecomposition} can only find the solution for
028     * square matrices and when the solution is an exact linear solution, i.e. when
029     * ||A &times; X - B|| is exactly 0. Other solvers can also find solutions
030     * with non-square matrix A and with non-null minimal norm. If an exact linear
031     * solution exists it is also the minimal norm solution.</p>
032     *
033     * @version $Id: DecompositionSolver.java 1416643 2012-12-03 19:37:14Z tn $
034     * @since 2.0
035     */
036    public interface DecompositionSolver {
037    
038        /** Solve the linear equation A &times; X = B for matrices A.
039         * <p>The A matrix is implicit, it is provided by the underlying
040         * decomposition algorithm.</p>
041         * @param b right-hand side of the equation A &times; X = B
042         * @return a vector X that minimizes the two norm of A &times; X - B
043         * @throws org.apache.commons.math3.exception.DimensionMismatchException
044         * if the matrices dimensions do not match.
045         * @throws SingularMatrixException
046         * if the decomposed matrix is singular.
047         */
048        RealVector solve(final RealVector b);
049    
050        /** Solve the linear equation A &times; X = B for matrices A.
051         * <p>The A matrix is implicit, it is provided by the underlying
052         * decomposition algorithm.</p>
053         * @param b right-hand side of the equation A &times; X = B
054         * @return a matrix X that minimizes the two norm of A &times; X - B
055         * @throws org.apache.commons.math3.exception.DimensionMismatchException
056         * if the matrices dimensions do not match.
057         * @throws SingularMatrixException
058         * if the decomposed matrix is singular.
059         */
060        RealMatrix solve(final RealMatrix b);
061    
062        /**
063         * Check if the decomposed matrix is non-singular.
064         * @return true if the decomposed matrix is non-singular.
065         */
066        boolean isNonSingular();
067    
068        /** Get the inverse (or pseudo-inverse) of the decomposed matrix.
069         * @return inverse matrix
070         * @throws SingularMatrixException
071         * if the decomposed matrix is singular.
072         */
073        RealMatrix getInverse();
074    }