    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.math.linear;
    019
    020
    021
    022    /**
    023     * Interface handling decomposition algorithms that can solve A &times; 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 $Revision: 811685 $ $Date: 2009-09-05 19:36:48 +0200 (sam. 05 sept. 2009) $
    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         * @exception IllegalArgumentException if matrices dimensions don't match
    044         * @exception InvalidMatrixException if decomposed matrix is singular
    045         */
    046        double[] solve(final double[] b)
    047            throws IllegalArgumentException, InvalidMatrixException;
    048
    049        /** Solve the linear equation A &times; X = B for matrices A.
    050         * <p>The A matrix is implicit, it is provided by the underlying
    051         * decomposition algorithm.</p>
    052         * @param b right-hand side of the equation A &times; X = B
    053         * @return a vector X that minimizes the two norm of A &times; X - B
    054         * @exception IllegalArgumentException if matrices dimensions don't match
    055         * @exception InvalidMatrixException if decomposed matrix is singular
    056         */
    057        RealVector solve(final RealVector b)
    058            throws IllegalArgumentException, InvalidMatrixException;
    059
    060        /** Solve the linear equation A &times; X = B for matrices A.
    061         * <p>The A matrix is implicit, it is provided by the underlying
    062         * decomposition algorithm.</p>
    063         * @param b right-hand side of the equation A &times; X = B
    064         * @return a matrix X that minimizes the two norm of A &times; X - B
    065         * @exception IllegalArgumentException if matrices dimensions don't match
    066         * @exception InvalidMatrixException if decomposed matrix is singular
    067         */
    068        RealMatrix solve(final RealMatrix b)
    069            throws IllegalArgumentException, InvalidMatrixException;
    070
    071        /**
    072         * Check if the decomposed matrix is non-singular.
    073         * @return true if the decomposed matrix is non-singular
    074         */
    075        boolean isNonSingular();
    076
    077        /** Get the inverse (or pseudo-inverse) of the decomposed matrix.
    078         * @return inverse matrix
    079         * @throws InvalidMatrixException if decomposed matrix is singular
    080         */
    081        RealMatrix getInverse()
    082            throws InvalidMatrixException;
    083
    084    }