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 import org.apache.commons.math.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 LUDecomposition} 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 $Revision: 781122 $ $Date: 2009-06-02 20:53:23 +0200 (mar. 02 juin 2009) $ 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 * @exception IllegalArgumentException if matrices dimensions don't match 046 * @exception InvalidMatrixException if decomposed matrix is singular 047 */ 048 T[] solve(final T[] b) 049 throws IllegalArgumentException, InvalidMatrixException; 050 051 /** Solve the linear equation A × X = B for matrices A. 052 * <p>The A matrix is implicit, it is provided by the underlying 053 * decomposition algorithm.</p> 054 * @param b right-hand side of the equation A × X = B 055 * @return a vector X that minimizes the two norm of A × X - B 056 * @exception IllegalArgumentException if matrices dimensions don't match 057 * @exception InvalidMatrixException if decomposed matrix is singular 058 */ 059 FieldVector<T> solve(final FieldVector<T> b) 060 throws IllegalArgumentException, InvalidMatrixException; 061 062 /** Solve the linear equation A × X = B for matrices A. 063 * <p>The A matrix is implicit, it is provided by the underlying 064 * decomposition algorithm.</p> 065 * @param b right-hand side of the equation A × X = B 066 * @return a matrix X that minimizes the two norm of A × X - B 067 * @exception IllegalArgumentException if matrices dimensions don't match 068 * @exception InvalidMatrixException if decomposed matrix is singular 069 */ 070 FieldMatrix<T> solve(final FieldMatrix<T> b) 071 throws IllegalArgumentException, InvalidMatrixException; 072 073 /** 074 * Check if the decomposed matrix is non-singular. 075 * @return true if the decomposed matrix is non-singular 076 */ 077 boolean isNonSingular(); 078 079 /** Get the inverse (or pseudo-inverse) of the decomposed matrix. 080 * @return inverse matrix 081 * @throws InvalidMatrixException if decomposed matrix is singular 082 */ 083 FieldMatrix<T> getInverse() 084 throws InvalidMatrixException; 085 086 }