Runge-Kutta method: Difference between revisions

Content added Content deleted
Line 316: Line 316:
y[i + 1] = y[i] + (dy1 + 2 * dy2 + 2 * dy3 + dy4) / 6;
y[i + 1] = y[i] + (dy1 + 2 * dy2 + 2 * dy3 + dy4) / 6;


double error = y[i + 1] - solution(s[i + 1]);
double error = Math.Abs(y[i + 1] - solution(s[i + 1]));
double t_rounded = Math.Round(t + dt, 10);
double t_rounded = Math.Round(t + dt, 2);


if (Math.Round(t + dt, 1) % 1 == 0)
if (t_rounded % 1 == 0)
{
{
Console.WriteLine(" y(" + t_rounded + ")" + " " + y[i + 1] + " ".PadRight(5) + Math.Abs(error));
Console.WriteLine(" y(" + t_rounded + ")" + " " + y[i + 1] + " ".PadRight(5) + (error));
}
}