001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
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 *
010 *
011 * Unless required by applicable law or agreed to in writing, software
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
018package org.apache.commons.math4.field.linalg;
019
020/**
021 * Interface handling decomposition algorithms that can solve {@code A X = B}.
022 *
023 * <p>Decomposition algorithms decompose an A matrix has a product of several specific
024 * matrices from which they can solve the above system of equations in a least-squares
025 * sense: Find X such that {@code ||A X - B||} is minimal.</p>
026 *
027 * <p>Some solvers like {@link FieldLUDecomposition} can only find the solution for
028 * square matrices and when the solution is an exact linear solution, i.e. when
029 * {@code ||A X - B||} is exactly 0.
030 * Other solvers can also find solutions with non-square matrix {@code A} and with
031 * non-zero minimal norm.
032 * If an exact linear solution exists it is also the minimal norm solution.</p>
033 *
034 * @param <T> Type of the field elements.
035 *
036 * @since 4.0
037 */
038public interface FieldDecompositionSolver<T> {
039    /**
040     * Solves the linear equation {@code A X = B}.
041     *
042     * <p>Matrix {@code A} is implicit: It is provided by the underlying
043     * decomposition algorithm.</p>
044     *
045     * @param b Right-hand side of the equation.
046     * @return the matrix {@code X} that minimizes {@code ||A X - B||}.
047     * @throws IllegalArgumentException if the dimensions do not match.
048     */
049    FieldDenseMatrix<T> solve(final FieldDenseMatrix<T> b);
050
051    /**
052     * Computes the inverse of a decomposed (square) matrix.
053     *
054     * @return the inverse matrix.
055     */
056    FieldDenseMatrix<T> getInverse();
057}