6 #ifndef realroot_SOLVE_SBDSLV_LINEAR_DOOLITTLE_HPP
7 #define realroot_SOLVE_SBDSLV_LINEAR_DOOLITTLE_HPP
16 template<
typename real_t >
17 void Lsolve(real_t * x , real_t
const *
const L, real_t
const *
const b,
unsigned n )
19 for (
unsigned i = 0; i < n ; i ++ )
22 for (
unsigned j = 0; j < i; j ++ ) sum += L[i*n+j]*x[j];
27 template<
typename real_t >
28 bool Usolve( real_t * x, real_t
const *
const U, real_t
const *
const b,
unsigned n )
30 for (
int i = n-1; i >=0 ; i -- )
33 for (
int j = n-1; j > i; j -- ) sum += U[i*n+j]*x[j];
35 x[i] = (b[i]-
sum)/U[i*n+i];
40 template<
typename real_t >
41 bool doolittle( real_t
const *
const A, real_t * L, real_t * U,
unsigned n )
44 for ( k = 0; k < n; k++ )
47 for ( i = k; i < n; i ++ )
49 U[ k*n + i ] = A[ k*n + i ];
50 for ( p = 0; p < k; p ++ ) U[ k*n + i ] -= L[ k*n + p ]*U[ p*n + i ];
52 for ( i = k + 1; i < n; i ++ )
56 for ( p = 0; p < k; p ++ ) sum += L[i*n+p]*U[p*n+k];
57 L[i*n+k] = (A[i*n + k] -
sum)/U[ k*n + k ];
63 template<
typename real_t >
64 bool LUsolve( real_t * x, real_t
const *
const M, real_t
const *
const b,
unsigned n )
68 if ( !
doolittle( M, tmp, tmp, n ) )
return false;
70 return Usolve( x, tmp, xtmp, n );
73 template<
typename real_t >
74 bool LUinverse( real_t * iM, real_t
const *
const M,
unsigned n )
82 if ( !
doolittle( M, lu, lu, n ) )
return false;
83 for (
unsigned c = 0;
c < n;
c ++ )
85 if (
c > 0) b[
c-1] = 0;
88 if ( !
Usolve( tmp, lu, xtmp, n ) )
return false;
89 for (
unsigned i = 0; i < n; i ++ ) iM[ i*n +
c ] = tmp[i];
Definition: system_epsilon.hpp:19
void fill(C *a, unsigned n, int s, const C &x)
Definition: tensor_vctops.hpp:152
const C & b
Definition: Interval_glue.hpp:25
bool doolittle(real_t const *const A, real_t *L, real_t *U, unsigned n)
Definition: linear_doolittle.hpp:41
bool Usolve(real_t *x, real_t const *const U, real_t const *const b, unsigned n)
Definition: linear_doolittle.hpp:28
void Lsolve(real_t *x, real_t const *const L, real_t const *const b, unsigned n)
Definition: linear_doolittle.hpp:17
real_t sum(real_t const *const src, unsigned sz, int st=1)
Definition: loops_vctops.hpp:197
void abs(Interval< C, r > &x, const Interval< C, r > &a)
Definition: Interval_fcts.hpp:185
bool LUsolve(real_t *x, real_t const *const M, real_t const *const b, unsigned n)
Definition: linear_doolittle.hpp:64
const C & c
Definition: Interval_glue.hpp:45
bool LUinverse(real_t *iM, real_t const *const M, unsigned n)
Definition: linear_doolittle.hpp:74