|Function||solve a linear system MA * X = B; in case the system is singular, get one solution out of the infinite solution space|
|Syntax C/C++||#include <MFstd.h>|
int MF_safeSolve( fVector X, fMatrix MA, fVector B, ui len );
|C++ MatObj||#include <OptiVec.h>|
void vector<T>::safeSolve( const matrix<T>& MA, const vector<T>& B );
function MF_safeSolve( X:fVector; MA:fMatrix; B:fVector; len:UIntSize ):Integer;
|Description||MF_safeSolve is similar to MF_solve with the difference that, in case there is no unique solution of the linear system (i.e., LU decomposition fails), singular value decomposition is employed to obtain at least one solution out of the infinite solution space. Recall that the problem with singular linear systems is not that they don't have a solution, but rather that they are under-determined and have infinitely many solutions. In other words, one or more elements of the solution vector can be chosen arbitrarily. This is what MF_safeSolve does, with the additional constraint that the "smallest" solution vector in the least-squares sense is determined.
A return value of 0 indicates success via LUD, 1 signals success via SVD, and -1 is returned in the very rare case that even SVD fails.
MatrixLib Table of Contents OptiVec home