Fn_solve

Functions

template<typename eT , typename T1 , typename T2 >
bool solve (Mat< eT > &X, const Base< eT, T1 > &A_in, const Base< eT, T2 > &B_in)
 Solve a system of linear equations, i.e., A*X = B, where X is unknown. For a square matrix A, this function is conceptually the same as X = inv(A)*B, but is done more efficiently. The number of rows in A and B must be the same. B can be either a column vector or a matrix. This function will also try to provide approximate solutions to under-determined as well as over-determined systems (non-square A matrices).
template<typename eT , typename T1 , typename T2 >
Mat< eT > solve (const Base< eT, T1 > &A_in, const Base< eT, T2 > &B_in)

Function Documentation

template<typename eT , typename T1 , typename T2 >
bool solve ( Mat< eT > &  X,
const Base< eT, T1 > &  A_in,
const Base< eT, T2 > &  B_in 
) [inline]

Solve a system of linear equations, i.e., A*X = B, where X is unknown. For a square matrix A, this function is conceptually the same as X = inv(A)*B, but is done more efficiently. The number of rows in A and B must be the same. B can be either a column vector or a matrix. This function will also try to provide approximate solutions to under-determined as well as over-determined systems (non-square A matrices).

Definition at line 33 of file fn_solve.hpp.

References Base< elem_type, derived >::get_ref(), Mat< eT >::n_rows, auxlib::solve(), auxlib::solve_od(), and auxlib::solve_ud().

Referenced by solve().

00034   {
00035   arma_extra_debug_sigprint();
00036   
00037   const unwrap<T1> tmp1(A_in.get_ref());
00038   const unwrap<T2> tmp2(B_in.get_ref());
00039   
00040   const Mat<eT>& A = tmp1.M;
00041   const Mat<eT>& B = tmp2.M;
00042   
00043   arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in A and B must be the same" );
00044   
00045   if(A.n_rows == A.n_cols)
00046     {
00047     return auxlib::solve(X, A, B);
00048     }
00049   else
00050   if(A.n_rows > A.n_cols)
00051     {
00052     arma_extra_debug_print("solve(): detected over-determined system");
00053     return auxlib::solve_od(X, A, B);
00054     }
00055   else
00056     {
00057     arma_extra_debug_print("solve(): detected under-determined system");
00058     return auxlib::solve_ud(X, A, B);
00059     }
00060   }

template<typename eT , typename T1 , typename T2 >
Mat<eT> solve ( const Base< eT, T1 > &  A_in,
const Base< eT, T2 > &  B_in 
) [inline]

Definition at line 67 of file fn_solve.hpp.

References arma_print(), and solve().

00068   {
00069   arma_extra_debug_sigprint();
00070   
00071   Mat<eT> X;
00072   bool info = solve(X, A_in, B_in);
00073   
00074   if(info == false)
00075     {
00076     arma_print("solve(): solution not found");
00077     }
00078   
00079   return X;
00080   }