|
void | forward_euler_step (const double dx, const double x, std::valarray< double > *y, std::valarray< double > *dy) |
| Compute next step approximation using the forward-Euler method. More...
|
|
double | forward_euler (double dx, double x0, double x_max, std::valarray< double > *y, bool save_to_file=false) |
| Compute approximation using the forward-Euler method in the given limits. More...
|
|
void | midpoint_euler_step (const double dx, const double &x, std::valarray< double > *y, std::valarray< double > *dy) |
| Compute next step approximation using the midpoint-Euler method. More...
|
|
double | midpoint_euler (double dx, double x0, double x_max, std::valarray< double > *y, bool save_to_file=false) |
| Compute approximation using the midpoint-Euler method in the given limits. More...
|
|
void | semi_implicit_euler_step (const double dx, const double &x, std::valarray< double > *y, std::valarray< double > *dy) |
| Compute next step approximation using the semi-implicit-Euler method. More...
|
|
double | semi_implicit_euler (double dx, double x0, double x_max, std::valarray< double > *y, bool save_to_file=false) |
| Compute approximation using the semi-implicit-Euler method in the given limits. More...
|
|
Integration functions for implementations with solving ordinary differential equations (ODEs) of any order and and any number of independent variables.
◆ forward_euler()
double forward_euler |
( |
double |
dx, |
|
|
double |
x0, |
|
|
double |
x_max, |
|
|
std::valarray< double > * |
y, |
|
|
bool |
save_to_file = false |
|
) |
| |
Compute approximation using the forward-Euler method in the given limits.
- Parameters
-
[in] | dx | step size |
[in] | x0 | initial value of independent variable |
[in] | x_max | final value of independent variable |
[in,out] | y | take \(y_n\) and compute \(y_{n+1}\) |
[in] | save_to_file | flag to save results to a CSV file (1) or not (0) |
- Returns
- time taken for computation in seconds
108 fp.
open(
"forward_euler.csv", std::ofstream::out);
121 if (save_to_file && fp.
is_open()) {
124 for (
int i = 0; i < L - 1; i++) {
125 fp << y[0][i] <<
",";
127 fp << y[0][L - 1] <<
"\n";
132 }
while (x <= x_max);
140 return static_cast<double>(t2 - t1) / CLOCKS_PER_SEC;
◆ forward_euler_step()
Compute next step approximation using the forward-Euler method.
\[y_{n+1}=y_n + dx\cdot f\left(x_n,y_n\right)\]
- Parameters
-
[in] | dx | step size |
[in] | x | take \(x_n\) and compute \(x_{n+1}\) |
[in,out] | y | take \(y_n\) and compute \(y_{n+1}\) |
[in,out] | dy | compute \(f\left(x_n,y_n\right)\) |
◆ midpoint_euler()
double midpoint_euler |
( |
double |
dx, |
|
|
double |
x0, |
|
|
double |
x_max, |
|
|
std::valarray< double > * |
y, |
|
|
bool |
save_to_file = false |
|
) |
| |
Compute approximation using the midpoint-Euler method in the given limits.
- Parameters
-
[in] | dx | step size |
[in] | x0 | initial value of independent variable |
[in] | x_max | final value of independent variable |
[in,out] | y | take \(y_n\) and compute \(y_{n+1}\) |
[in] | save_to_file | flag to save results to a CSV file (1) or not (0) |
- Returns
- time taken for computation in seconds
113 fp.
open(
"midpoint_euler.csv", std::ofstream::out);
125 if (save_to_file && fp.
is_open()) {
128 for (
int i = 0; i < L - 1; i++) {
129 fp << y[0][i] <<
",";
131 fp << y[0][L - 1] <<
"\n";
136 }
while (x <= x_max);
143 return static_cast<double>(t2 - t1) / CLOCKS_PER_SEC;
◆ midpoint_euler_step()
Compute next step approximation using the midpoint-Euler method.
\[y_{n+1} = y_n + dx\, f\left(x_n+\frac{1}{2}dx, y_n + \frac{1}{2}dx\,f\left(x_n,y_n\right)\right)\]
- Parameters
-
[in] | dx | step size |
[in] | x | take \(x_n\) and compute \(x_{n+1}\) |
[in,out] | y | take \(y_n\) and compute \(y_{n+1}\) |
[in,out] | dy | compute \(f\left(x_n,y_n\right)\) |
88 double tmp_x = x + 0.5 * dx;
◆ semi_implicit_euler()
double semi_implicit_euler |
( |
double |
dx, |
|
|
double |
x0, |
|
|
double |
x_max, |
|
|
std::valarray< double > * |
y, |
|
|
bool |
save_to_file = false |
|
) |
| |
Compute approximation using the semi-implicit-Euler method in the given limits.
- Parameters
-
[in] | dx | step size |
[in] | x0 | initial value of independent variable |
[in] | x_max | final value of independent variable |
[in,out] | y | take \(y_n\) and compute \(y_{n+1}\) |
[in] | save_to_file | flag to save results to a CSV file (1) or not (0) |
- Returns
- time taken for computation in seconds
110 fp.
open(
"semi_implicit_euler.csv", std::ofstream::out);
122 if (save_to_file && fp.
is_open()) {
125 for (
int i = 0; i < L - 1; i++) {
126 fp << y[0][i] <<
",";
128 fp << y[0][L - 1] <<
"\n";
133 }
while (x <= x_max);
140 return static_cast<double>(t2 - t1) / CLOCKS_PER_SEC;
◆ semi_implicit_euler_step()
Compute next step approximation using the semi-implicit-Euler method.
\[y_{n+1}=y_n + dx\cdot f\left(x_n,y_n\right)\]
- Parameters
-
[in] | dx | step size |
[in] | x | take \(x_n\) and compute \(x_{n+1}\) |
[in,out] | y | take \(y_n\) and compute \(y_{n+1}\) |
[in,out] | dy | compute \(f\left(x_n,y_n\right)\) |
86 y[0][0] += dx * dy[0][0];