Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cholesky.hpp
Go to the documentation of this file.
1 
2 /*
3  - begin : 2005-08-24
4  - copyright : (C) 2005 by Gunter Winkler, Konstantin Kutzkow
5  - email : guwi17@gmx.de
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 3.0 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 */
22 
23 #include <cassert>
24 
25 #include <boost/numeric/ublas/vector.hpp>
26 #include <boost/numeric/ublas/vector_proxy.hpp>
27 
28 #include <boost/numeric/ublas/matrix.hpp>
29 #include <boost/numeric/ublas/matrix_proxy.hpp>
30 
31 
32 namespace ublas = boost::numeric::ublas;
33 
34 
44 template < class MATRIX, class TRIA >
45 size_t cholesky_decompose( const MATRIX& A, TRIA& L )
46 {
47  using namespace ublas;
48 
49  typedef typename MATRIX::value_type T;
50 
51  assert( A.size1() == A.size2() );
52  assert( A.size1() == L.size1() );
53  assert( A.size2() == L.size2() );
54 
55  const size_t n = A.size1();
56 
57  for ( size_t k=0 ; k < n; k++ )
58  {
59 
60  double qL_kk = A( k,k ) - inner_prod( project( row( L, k ), range( 0, k ) ),
61  project( row( L, k ), range( 0, k ) ) );
62 
63  if ( qL_kk <= 0 )
64  {
65  return 1 + k;
66  }
67 
68  else
69  {
70  double L_kk = sqrt( qL_kk );
71  L( k,k ) = L_kk;
72 
73  matrix_column<TRIA> cLk( L, k );
74  project( cLk, range( k+1, n ) )
75  = ( project( column( A, k ), range( k+1, n ) )
76  - prod( project( L, range( k+1, n ), range( 0, k ) ),
77  project( row( L, k ), range( 0, k ) ) ) ) / L_kk;
78  }
79  }
80 
81  return 0;
82 }

Generated on Fri Oct 25 2013 14:24:04 for Feel++ by doxygen 1.8.4