From 769ef0e8910bf8c6a1f06d02a172d8aed150398d Mon Sep 17 00:00:00 2001 From: algobytewise Date: Mon, 8 Mar 2021 20:56:20 +0530 Subject: [PATCH] Adjusted looping to include the endpoint --- Maths/EulerMethod.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Maths/EulerMethod.js b/Maths/EulerMethod.js index 6cb077b4f..472aff156 100644 --- a/Maths/EulerMethod.js +++ b/Maths/EulerMethod.js @@ -28,7 +28,7 @@ function eulerFull (xStart, xEnd, stepSize, yStart, differentialEquation) { let yCurrent = yStart let xCurrent = xStart - while (xCurrent <= xEnd - stepSize) { + while (xCurrent < xEnd) { // Euler method for next step yCurrent = eulerStep(xCurrent, stepSize, yCurrent, differentialEquation) xCurrent += stepSize @@ -86,7 +86,7 @@ function exampleEquation3 (x, y) { } const points1 = eulerFull(0, 4, 0.1, 0, exampleEquation1) -const points2 = eulerFull(0, 4.1, 0.1, 1, exampleEquation2) +const points2 = eulerFull(0, 4, 0.1, 1, exampleEquation2) const points3 = eulerFull(0, 0.1, 0.025, 1, exampleEquation3) console.log(points1)