comparison armadillo-2.4.4/include/armadillo_bits/fn_solve.hpp @ 0:8b6102e2a9b0

Armadillo Library
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 09:27:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8b6102e2a9b0
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-2011 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12
13
14 //! \addtogroup fn_solve
15 //! @{
16
17
18
19 //! Solve a system of linear equations, i.e., A*X = B, where X is unknown.
20 //! For a square matrix A, this function is conceptually the same as X = inv(A)*B,
21 //! but is done more efficiently.
22 //! The number of rows in A and B must be the same.
23 //! B can be either a column vector or a matrix.
24 //! This function will also try to provide approximate solutions
25 //! to under-determined as well as over-determined systems (non-square A matrices).
26
27 template<typename T1, typename T2>
28 inline
29 const Glue<T1, T2, glue_solve>
30 solve
31 (
32 const Base<typename T1::elem_type,T1>& A,
33 const Base<typename T1::elem_type,T2>& B,
34 const bool slow = false,
35 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
36 )
37 {
38 arma_extra_debug_sigprint();
39 arma_ignore(junk);
40
41 return Glue<T1, T2, glue_solve>(A.get_ref(), B.get_ref(), ((slow == false) ? 0 : 1) );
42 }
43
44
45
46 template<typename T1, typename T2>
47 inline
48 const Glue<T1, T2, glue_solve_tr>
49 solve
50 (
51 const Op<T1, op_trimat>& A,
52 const Base<typename T1::elem_type,T2>& B,
53 const bool slow = false,
54 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
55 )
56 {
57 arma_extra_debug_sigprint();
58 arma_ignore(slow);
59 arma_ignore(junk);
60
61 return Glue<T1, T2, glue_solve_tr>(A.m, B.get_ref(), A.aux_uword_a);
62 }
63
64
65
66 template<typename T1, typename T2>
67 inline
68 bool
69 solve
70 (
71 Mat<typename T1::elem_type>& out,
72 const Base<typename T1::elem_type,T1>& A,
73 const Base<typename T1::elem_type,T2>& B,
74 const bool slow = false,
75 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
76 )
77 {
78 arma_extra_debug_sigprint();
79 arma_ignore(junk);
80
81 try
82 {
83 out = solve( A.get_ref(), B.get_ref(), slow );
84 }
85 catch(std::runtime_error&)
86 {
87 return false;
88 }
89
90 return true;
91 }
92
93
94
95 //! @}