From 72c9b26a13f9c08b7279dc5ceddb30762706b9ae Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Thu, 11 Jun 2020 12:40:56 -0400 Subject: [PATCH] corected implicit euler function --- numerical_methods/ode_semi_implicit_euler.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/numerical_methods/ode_semi_implicit_euler.c b/numerical_methods/ode_semi_implicit_euler.c index b01fb53c..ce629941 100644 --- a/numerical_methods/ode_semi_implicit_euler.c +++ b/numerical_methods/ode_semi_implicit_euler.c @@ -84,17 +84,16 @@ void exact_solution(const double *x, double *y) */ void semi_implicit_euler_step(double dx, double *x, double *y, double *dy) { - problem(x, y, dy); - double tmp_x = (*x) + 0.5 * dx; - double tmp_y[order]; int o; - for (o = 0; o < order; o++) - tmp_y[o] = y[o] + 0.5 * dx * dy[o]; - problem(&tmp_x, tmp_y, dy); + problem(x, y, dy); // update dy once + y[0] += dx * dy[0]; // update y0 - for (o = 0; o < order; o++) - y[o] += dx * dy[o]; + problem(x, y, dy); // update dy once more + + for (o = 1; o < order; o++) + y[o] += dx * dy[o]; // update remaining using new dy + *x += dx; } /**