6 #ifndef TBCI_SOLVER_EXPM_H
7 #define TBCI_SOLVER_EXPM_H
9 #include "tbci/basics.h"
10 #include "tbci/matrix.h"
17 template <typename Matrix>
23 for (
unsigned int i=0;
i<mat.
rows(); ++
i) {
25 for (
unsigned int j=1; j<mat.
columns(); ++j)
40 for (
unsigned int i=0;
i<mat.
rows(); ++
i) {
42 for (
unsigned int j=1; j<mat.
columns(); ++j)
56 template<typename Matrix>
62 unsigned int dim = exponent.
rows();
69 for(
unsigned int j=0;j<dim;j++) eye(j,j)=1.0;
72 double z_norm =
norm_1(exponent);
75 temp /= (
pow(2.0, s));
88 c = c*(q-k+1)/(k*(2*q-k+1));
103 for(k=1;k<=s;k++) E = E*E;
115 template<typename MatrixIn, typename MatrixOut>
116 void expm2 (
const MatrixIn& exponent, MatrixOut& erg,
double ERROR=1e-3)
118 unsigned int dim=exponent.rows();
122 double z_norm=
norm_1(exponent);
125 MatrixIn scaled(exponent);
126 double scale_factor = (
pow(2.0, s));
127 scaled/=scale_factor;
134 MatrixOut temp(scaled);
139 for (
unsigned int j=0; j<dim; j++) erg(j,j) += 1;
143 for(i=2; i<100 && error>ERROR; i++)
145 temp = (temp/
i)*scaled;
154 for(
int k=1;k<=s;k++) erg = erg*erg;
166 template<typename MatrixIn, typename MatrixOut>
167 void expm3 (
const MatrixIn& exponent, MatrixOut& erg,
double ERROR=1e-3)
169 unsigned int dim=exponent.rows();
173 for (
unsigned int i=0;
i<dim;
i++)
174 for (
unsigned int j=0; j<dim; j++)
182 double scale_factor = (
pow(2.0, s));
185 MatrixOut temp(exponent);
189 for(
int iter=0; iter<100 && error>ERROR; iter+=4)
193 scale_factor = (
pow(2.0, s));
194 erg = exponent/(scale_factor);
195 for(
unsigned int j=0; j<dim; j++) erg(j,j) += 1;
196 for(
int k=1;k<=s;k++)
198 error =
norm_1 (erg - temp);
T sum(const FS_Vector< dims, T > &fv)
const Vector< T > const Vector< T > const Vector< T > & p
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
F_TMatrix< double > lu_solve(const F_Matrix< double > &A, const F_Matrix< double > &B, int overwriteA=0)
void mark_destroy() const
mark destructible
T max(const FS_Vector< dims, T > &fv)
Matrix< T > class NN friend void expm3(const BdMatrix< T > &exponent, Matrix< T > &erg, double)
void expm(const Matrix &exponent, Matrix &E)
unsigned int columns() const
number of columns
NAMESPACE_TBCI double norm_1(const Matrix &mat)
Matrix< T > class NN friend void expm2(const BdMatrix< T > &exponent, Matrix< T > &erg, double)
TBCI__ cplx< T > pow(const TBCI__ cplx< T > &z, const double n)
tbci_traits< T >::const_refval_type get(const unsigned r, const unsigned c) const
get, set and getcref are used internally and not for public consumption
unsigned int rows() const
number of rows