MF_safeSolve MD_safeSolve ME_safeSolve
Functionsolve 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 );
int MF_safeSolvewEdit( fVector X, fMatrix MA, fVector B, ui len, float thresh );
C++ MatObj#include <OptiVec.h>
void vector<T>::safeSolve( const matrix<T>& MA, const vector<T>& B );
void vector<T>::safeSolvewEdit( const matrix<T>& MA, const vector<T>& B, T thresh );
Pascal/Delphiuses MFstd;
function MF_safeSolve( X:fVector; MA:fMatrix; B:fVector; len:UIntSize ):Integer;
function MF_safeSolvewEdit( X:fVector; MA:fMatrix; B:fVector; len:UIntSize; thresh:Single ):Integer;
DescriptionMF_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.

The default threshold for the decision between LUD and SVD, as well as for the singular-value editing in the SVD branch may be changed by calling MF_SVDsetEdit. As MF_SVDsetEdit is not thread-safe, this function should not be used to set different editing thresholds for different calls to MF_safeSolve etc. Rather than repeatedly changing the default value, use the "wEdit" variant of MF_safeSolve etc., namely MF_safeSolvewEdit, MF_SVsolvewEdit and MF_solveBySVDwEdit.

See alsoMF_solve,   chapter 10

MatrixLib Table of Contents  OptiVec home