fn_solve.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup fn_solve
00018 //! @{
00019 
00020 
00021 
00022 //! Solve a system of linear equations, i.e., A*X = B, where X is unknown.
00023 //! For a square matrix A, this function is conceptually the same as X = inv(A)*B,
00024 //! but is done more efficiently.
00025 //! The number of rows in A and B must be the same.
00026 //! B can be either a column vector or a matrix.
00027 //! This function will also try to provide approximate solutions
00028 //! to under-determined as well as over-determined systems (non-square A matrices).
00029 
00030 template<typename T1, typename T2>
00031 inline
00032 const Glue<T1, T2, glue_solve>
00033 solve
00034   (
00035   const Base<typename T1::elem_type,T1>& A,
00036   const Base<typename T1::elem_type,T2>& B,
00037   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00038   )
00039   {
00040   arma_extra_debug_sigprint();
00041   
00042   return Glue<T1, T2, glue_solve>(A.get_ref(), B.get_ref());
00043   }
00044 
00045 
00046 
00047 template<typename T1, typename T2>
00048 inline
00049 bool
00050 solve
00051   (
00052   Mat<typename T1::elem_type>& out,
00053   const Base<typename T1::elem_type,T1>& A,
00054   const Base<typename T1::elem_type,T2>& B,
00055   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00056   )
00057   {
00058   arma_extra_debug_sigprint();
00059   
00060   out = solve(A,B);
00061   
00062   return (out.n_elem == 0) ? false : true;
00063   }
00064 
00065 
00066 
00067 //! @}