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.math4.legacy.field.linalg;
19
20 /**
21 * Interface handling decomposition algorithms that can solve {@code A X = B}.
22 *
23 * <p>Decomposition algorithms decompose an A matrix has a product of several specific
24 * matrices from which they can solve the above system of equations in a least-squares
25 * sense: Find X such that {@code ||A X - B||} is minimal.</p>
26 *
27 * <p>Some solvers like {@link FieldLUDecomposition} can only find the solution for
28 * square matrices and when the solution is an exact linear solution, i.e. when
29 * {@code ||A X - B||} is exactly 0.
30 * Other solvers can also find solutions with non-square matrix {@code A} and with
31 * non-zero minimal norm.
32 * If an exact linear solution exists it is also the minimal norm solution.</p>
33 *
34 * @param <T> Type of the field elements.
35 *
36 * @since 4.0
37 */
38 public interface FieldDecompositionSolver<T> {
39 /**
40 * Solves the linear equation {@code A X = B}.
41 *
42 * <p>Matrix {@code A} is implicit: It is provided by the underlying
43 * decomposition algorithm.</p>
44 *
45 * @param b Right-hand side of the equation.
46 * @return the matrix {@code X} that minimizes {@code ||A X - B||}.
47 * @throws IllegalArgumentException if the dimensions do not match.
48 */
49 FieldDenseMatrix<T> solve(FieldDenseMatrix<T> b);
50
51 /**
52 * Computes the inverse of a decomposed (square) matrix.
53 *
54 * @return the inverse matrix.
55 */
56 FieldDenseMatrix<T> getInverse();
57 }