33static double change(
double x,
double y) {
return ((x - y) / 2.0); }
57double rungeKutta(
double init_x,
const double &init_y,
const double &x,
67 auto n =
static_cast<uint64_t
>((x - init_x) /
h);
69 std::vector<double> k(4, 0.0);
74 for (
int i = 1; i <= n; ++i) {
78 k[1] =
h *
change(init_x + 0.5 *
h, y + 0.5 * k[0]);
79 k[2] =
h *
change(init_x + 0.5 *
h, y + 0.5 * k[1]);
80 k[3] =
h *
change(init_x +
h, y + k[2]);
84 y += (1.0 / 6.0) * (k[0] + 2 * k[1] + 2 * k[2] + k[3]);
101 std::cout <<
"The Runge Kutta function will be tested on the basis of "
102 "precomputed values\n";
104 std::cout <<
"Test 1...."
106 double valfirst = numerical_methods::runge_kutta::rungeKutta(
108 assert(valfirst == 3.10363932323749570);
109 std::cout <<
"Passed Test 1\n";
111 std::cout <<
"Test 2...."
113 double valsec = numerical_methods::runge_kutta::rungeKutta(
115 assert(valsec == 3.40600589380261409);
116 std::cout <<
"Passed Test 2\n";
118 std::cout <<
"Test 3...."
120 double valthird = numerical_methods::runge_kutta::rungeKutta(
122 assert(valthird == 2.49251005860244268);
123 std::cout <<
"Passed Test 3\n";
Functions for Runge Kutta fourth order method.
static double change(double x, double y)
asserting the test functions
double rungeKutta(double init_x, const double &init_y, const double &x, const double &h)
the Runge Kutta method finds the value of integration of a function in the given limits....
static void test()
Tests to check algorithm implementation.