16 unsigned int max_order = 100;
117 this->roots = import_data(
"code_files/roots.txt");
118 this->weights = import_data(
"code_files/weights.txt");
119 this->weights /= exp((this->roots ^ 2.0) * (-1.0));
138 unsigned int order = coefficients.get_rows();
139 Matrix<T> Hn_0(values), Hn_1(values), Hn(values), result(values);
144 result = Hn_0 * coefficients(0, 0) + Hn_1 * coefficients(1, 0);
147 for (
auto i = 2; i < order; i++) {
148 Hn = Hn_1 * values * 2.0 - Hn_0 * 2.0 * (i - 1.0);
151 result += (Hn * coefficients(i, 0));
167 T Hn_0, Hn_1, Hn, result;
168 unsigned int order = coefficients.get_rows();
171 result = Hn_0 * coefficients(0, 0) + Hn_1 * coefficients(1, 0);
174 for (
auto i = 2; i < order; i++) {
175 Hn = Hn_1 * value * 2.0 - Hn_0 * 2.0 * (i - 1.0);
178 result += Hn * coefficients(i, 0);
193 unsigned int order = coefficients.get_rows();
194 Matrix<T> new_coefficients(order - 1, 1);
197 for (
auto i = 1; i < order; i++) {
198 new_coefficients(i - 1, 0) = 2.0 * i * coefficients(i, 0);
201 return new_coefficients;
216 Matrix<T> deriv_coefficients = coefficients_deriv(coefficients);
217 return evaluate(deriv_coefficients, values);
232 Matrix<T> deriv_coefficients = coefficients_deriv(coefficients);
233 return evaluate(deriv_coefficients, value);
247 unsigned int rows, cols;
249 std::ifstream myfile;
251 myfile >> rows >> cols;
256 for (
auto i = 0; i < rows; i++) {
257 for (
auto j = 0; j < cols; j++) {
278 if (order >= max_order) {
279 std::cerr <<
"Maximum order exceeded!\n";
282 for (
auto i = 0; i < order; i++) {
283 roots(i, 0) = this->roots(order - 1, i);
301 if (order >= max_order) {
302 std::cerr <<
"Maximum order exceeded!\n";
305 for (
auto i = 0; i < order; i++) {
306 weights(i, 0) = this->weights(order - 1, i);
333 for (
auto i = 0; i < order; i++) {
334 func_values(i, 0) = *func(roots(i, 0));
338 for (
auto i = 0; i < order; i++) {
339 coefficients(i, 0) = weights.
tr().
dot(func_values)(0, 0) / std::pow(2, i) / factorial / std::sqrt(M_PI);
Class for computing Hermite polynomials and related operations.
Definition Hermite_Tools.h:11
Matrix< T > evaluate(Matrix< T > coefficients, Matrix< T > values)
Evaluates the Hermite polynomial at specified values.
Definition Hermite_Tools.h:136
Matrix< T > import_data(const char *file)
Imports data for roots or weights from a file.
Definition Hermite_Tools.h:246
Matrix< T > compute_coefficients(unsigned int order, T(*func)(T))
Computes the coefficients for the Hermite polynomial using a given function.
Definition Hermite_Tools.h:324
Matrix< T > get_roots(unsigned int order)
Retrieves the roots of the Hermite polynomial of specified order.
Definition Hermite_Tools.h:276
Matrix< T > coefficients_deriv(Matrix< T > coefficients)
Computes the derivative of the Hermite polynomial coefficients.
Definition Hermite_Tools.h:191
~Hermite()
Destructor for Hermite class.
Definition Hermite_Tools.h:126
Hermite()
Default constructor for Hermite class.
Definition Hermite_Tools.h:116
Matrix< T > get_weights(unsigned int order)
Retrieves the weights of the Hermite polynomial of specified order.
Definition Hermite_Tools.h:299
Matrix< T > evaluate_deriv(Matrix< T > coefficients, Matrix< T > values)
Evaluates the derivative of the Hermite polynomial at specified values.
Definition Hermite_Tools.h:215
This class implements a matrix object used for linear algebra and vectorized operations.
Definition Matrix.h:25
Matrix dot(const Matrix &other)
Calculates the dot product of two matrices.
Definition Matrix.h:604
Matrix tr()
Transposes the matrix.
Definition Matrix.h:705