35 return Record(
"PadeApproximant",
36 "Record with an information about pade approximant parameters." 37 "Note that stable method is guaranteed only if d-n=1 or d-n=2, " 38 "where d=degree of denominator and n=degree of nominator. " 39 "In those cases the Pade approximant corresponds to an implicit " 40 "Runge-Kutta method which is both A- and L-stable. " 41 "The default values n=2, d=3 yield relatively good precision " 42 "while keeping the order moderately low.")
45 "Polynomial degree of the nominator of Pade approximant.")
47 "Polynomial degree of the denominator of Pade approximant")
52 Input::register_class< PadeApproximant, Input::Record >(
"PadeApproximant") +
57 nominator_degree_ = in_rec.
val<
int>(
"pade_nominator_degree");
58 denominator_degree_ = in_rec.
val<
int>(
"pade_denominator_degree");
59 if (nominator_degree_+1 != denominator_degree_ &&
60 nominator_degree_+2 != denominator_degree_)
61 WarningOut() <<
"Pade approximation can be unstable since (denominator_degree-nominator_degree) is not 1 or 2.\n";
65 : nominator_degree_(nominator_degree), denominator_degree_(denominator_degree)
90 OLD_ASSERT(matrix.n_rows == matrix.n_cols,
"Matrix is not square.");
92 unsigned int size = matrix.n_rows;
95 arma::mat nominator_matrix(size, size),
96 denominator_matrix(size, size);
98 nominator_matrix.fill(0);
99 denominator_matrix.fill(0);
110 matrix = nominator_matrix * inv(denominator_matrix);
114 unsigned int denominator_degree,
121 for(
unsigned int i = 1; i < factorials.size(); i++)
122 factorials[i] = factorials[i-1]*i;
126 for(
int j = nominator_degree; j >= 0; j--)
129 (double)(factorials[nominator_degree + denominator_degree - j] * factorials[nominator_degree])
130 / (factorials[nominator_degree + denominator_degree] * factorials[j] * factorials[nominator_degree - j]);
133 for(
int i = denominator_degree; i >= 0; i--)
135 if(i % 2 == 0) sign = 1;
else sign = -1;
136 denominator_coefs[i] = sign *
137 (double)(factorials[nominator_degree + denominator_degree - i] * factorials[denominator_degree])
138 / (factorials[nominator_degree + denominator_degree] * factorials[i] * factorials[denominator_degree - i]);
143 const arma::mat& input_matrix,
146 arma::mat identity = arma::eye(input_matrix.n_rows, input_matrix.n_cols);
149 for(
int i = coefs.size()-1; i >= 0; i--)
151 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...
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.
static const Input::Type::Record & get_input_type()
#define START_TIMER(tag)
Starts a timer with specified tag.
static const int registrar
Registrar of class to factory.
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 .
#define WarningOut()
Macro defining 'warning' record of log.