MF_solve MD_solve ME_solve
MCF_solve MCD_solve MCE_solve
Functionsolve a linear system
Syntax C/C++#include <MFstd.h>
int MF_solve( fVector X, fMatrix MA, fVector B, ui len );
int MF_solvewEdit( fVector X, fMatrix MA, fVector B, ui len, float thresh );
int MCF_solvewEdit( cfVector X, cfMatrix MA, cfVector B, ui len, float thresh );
C++ MatObj#include <OptiVec.h>
void vector<T>::solve( const matrix<T>& MA, const vector<T>& B );
void vector<T>::solvewEdit( const matrix<T>& MA, const vector<T>& B, T thresh );
Pascal/Delphiuses MFstd;
function MF_solve( X:fVector; MA:fMatrix; B:fVector; len:UIntSize ): Integer;
function MF_solvewEdit( X:fVector; MA:fMatrix; B:fVector; len:UIntSize; thresh:Single ): Integer;
function MCF_solvewEdit( X:cfVector; MA:cfMatrix; B:cfVector; len:UIntSize; thresh:Single ): Integer;
DescriptionThis function solves the system MA * X = B of simultaneous linear equations, using LU decomposition. It works well in all cases where there is one unique solution. If successful, it returns FALSE (0).
If, on the other hand, the system is ill-determined, which happens in all cases where one or more of the equations are linear combinations of other equations of the same system, the resulting matrix becomes singular and the function fails with an error message.

To avoid outright failure in an application where ill-determined matrices might occur, you can define a minimum pivot for the decomposition. If you wish to do so for all calls to MF_LUdecompose and to the functions based upon it, namely MF_inv and MF_solve, you can do so by calling MF_LUDsetEdit. However, as this method is not thread-safe, you cannot use it in order to set different thresholds for different calls to the functions mentioned. Instead of defining a default editing threshold then, use their "wEdit" variants, i.e. MF_LUdecomposewEdit, MF_invwEdit or MF_solvewEdit. They take the desired threshold as the additional argument thresh. Note that thresh is always real, also in the complex versions.

The return value of MF_solve and MF_solvewEdit indicates if the linear system could successfully be solved:
Return valueMeaning
0Matrix MA is regular; linear system successfully solved
1Under-determined system; matrix MA is singular; result X contains no useful information
2Under-determined system; matrix MA is (nearly) singular; solution was achieved only by pivot editing. It depends on the specific application, iff the result is useful.

To check if MF_solve was successful, in single-thread programs, you may also call MF_LUDresult, whose return value will be FALSE (0), if the system could be solved without problems (and without pivot editing), and TRUE (1) for singular MA. In multi-thread programs, on the other hand, it would not be clear wich instance of MF_solve the call to MF_LUDresult would refer to. So, here, inspection of the return value of MF_solve is the only option.

As an often preferrable alternative to pivot editing, you might switch to MF_safeSolve or MF_solveBySVD.

Return valueCode 0, 1, or 2, see above
See alsoMF_LUdecompose,   MF_inv,   chapter 10

MatrixLib Table of Contents  OptiVec home