mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 02:05:08 +08:00
Adjusted looping to include the endpoint
This commit is contained in:
@ -28,7 +28,7 @@ function eulerFull (xStart, xEnd, stepSize, yStart, differentialEquation) {
|
|||||||
let yCurrent = yStart
|
let yCurrent = yStart
|
||||||
let xCurrent = xStart
|
let xCurrent = xStart
|
||||||
|
|
||||||
while (xCurrent <= xEnd - stepSize) {
|
while (xCurrent < xEnd) {
|
||||||
// Euler method for next step
|
// Euler method for next step
|
||||||
yCurrent = eulerStep(xCurrent, stepSize, yCurrent, differentialEquation)
|
yCurrent = eulerStep(xCurrent, stepSize, yCurrent, differentialEquation)
|
||||||
xCurrent += stepSize
|
xCurrent += stepSize
|
||||||
@ -86,7 +86,7 @@ function exampleEquation3 (x, y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const points1 = eulerFull(0, 4, 0.1, 0, exampleEquation1)
|
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)
|
const points3 = eulerFull(0, 0.1, 0.025, 1, exampleEquation3)
|
||||||
|
|
||||||
console.log(points1)
|
console.log(points1)
|
||||||
|
Reference in New Issue
Block a user