11 using namespace Input::Type;
15 =
Record(
"PadeApproximant",
"Record with an information about pade approximant parameters.")
18 "Polynomial degree of the nominator of Pade approximant.")
20 "Polynomial degree of the nominator of Pade approximant");
25 nominator_degree_ = in_rec.
val<
int>(
"nominator_degree");
26 denominator_degree_ = in_rec.
val<
int>(
"denominator_degree");
30 : nominator_degree_(nominator_degree), denominator_degree_(denominator_degree)
55 ASSERT(matrix.n_rows == matrix.n_cols,
"Matrix is not square.");
57 unsigned int size = matrix.n_rows;
60 arma::mat nominator_matrix(size, size),
61 denominator_matrix(size, size);
63 nominator_matrix.fill(0);
64 denominator_matrix.fill(0);
75 matrix = nominator_matrix * inv(denominator_matrix);
79 unsigned int denominator_degree,
86 for(
unsigned int i = 1; i < factorials.size(); i++)
87 factorials[i] = factorials[i-1]*i;
91 for(
int j = nominator_degree; j >= 0; j--)
94 (double)(factorials[nominator_degree + denominator_degree - j] * factorials[nominator_degree])
95 / (factorials[nominator_degree + denominator_degree] * factorials[j] * factorials[nominator_degree - j]);
98 for(
int i = denominator_degree; i >= 0; i--)
100 if(i % 2 == 0) sign = 1;
else sign = -1;
101 denominator_coefs[i] = sign *
102 (double)(factorials[nominator_degree + denominator_degree - i] * factorials[denominator_degree])
103 / (factorials[nominator_degree + denominator_degree] * factorials[i] * factorials[denominator_degree - i]);
108 const arma::mat& input_matrix,
111 arma::mat identity = arma::eye(input_matrix.n_rows, input_matrix.n_cols);
114 for(
int i = coefs.size()-1; i >= 0; i--)
116 polynomial_matrix = coefs[i] * identity + (polynomial_matrix * input_matrix);
arma::mat system_matrix_
the square matrix of ODE system
void approximate_matrix(arma::mat &matrix)
int nominator_degree_
Degree of the polynomial in the nominator.
void compute_exp_coefs(unsigned int nominator_degree, unsigned int denominator_degree, std::vector< double > &nominator_coefs, std::vector< double > &denominator_coefs)
Evaluates nominator and denominator coeficients of PadeApproximant for exponencial function...
static Input::Type::AbstractRecord input_type
static Input::Type::Record input_type
void update_solution(arma::vec &init_vector, arma::vec &output_vec) override
Updates solution of the ODEs system.
int denominator_degree_
Degree of the polynomial in the denominator.
Global macros to enhance readability and debugging, general constants.
PadeApproximant()
Hide default constructor.
#define START_TIMER(tag)
Starts a timer with specified tag.
bool step_changed_
flag is true if the step has been changed
void evaluate_matrix_polynomial(arma::mat &polynomial_matrix, const arma::mat &input_matrix, const std::vector< double > &coefs)
Evaluates the matrix polynomial by Horner scheme.
~PadeApproximant(void)
Destructor.
double step_
the step of the numerical method
arma::mat solution_matrix_
Solution matrix .