1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
// Run again with Runge-Kutta (variable order)
int stage = 4;
std::vector<double> weight = { 1.0 / 6.0, 1.0 / 3.0, 1.0 / 3.0, 1.0 / 6.0 };
std::vector<double> a = {
0.0, 0.0, 0.0, 0.0,
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0
};
std::vector<double> c = { 0.0, 0.5, 0.5, 1.0 };
ExplicitRKScheme ts(stage, a.data(), weight.data(), c.data();
ts.set_function_G(0, G0);
ts.set_function_G(1, G1);
for (int j = 1; j <= N; j++)
{
Y[j] = ts.one_step_march(h, t[j - 1], Y[j - 1]);
t[j] = t[j - 1] + h;
}
{
std::ofstream fileout("solrk.txt");
fileout << setprecision(10) << setiosflags(ios::scientific | ios::showpos);
for (int j = 0; j <= N; j++)
{
fileout << t[j] << " " << Y[j] << " " << exp(t[j]) << endl;
}
} // fileout closes itself here, no need for an explicit call to close.
|