GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — JavaScript/Maths/EulerMethod.js at master · TheAlgorithms/JavaScript Expand file tree/ Copy pathEulerMethod.jsMore file actions 36 lines (33 loc) · 1.49 KB / Copy pathEulerMethod.jsFile metadata and controls36 lines (33 loc) · 1.49 KB 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 33 34 35 36 /** * In mathematics and computational science, the Euler method (also called forward Euler method) is a first-order * numerical procedure for solving ordinary differential equations (ODEs) with a given initial value. It is the most * basic explicit method for numerical integration of ordinary differential equations. The method proceeds in a series * of steps. At each step the y-value is calculated by evaluating the differential equation at the previous step, * multiplying the result with the step-size and adding it to the last y-value: y_n+1 = y_n + stepSize * f(x_n, y_n). * * (description adapted from https://en.wikipedia.org/wiki/Euler_method) * @see https://www.geeksforgeeks.org/euler-method-solving-differential-equation/ */ export function eulerStep(xCurrent, stepSize, yCurrent, differentialEquation) { // calculates the next y-value based on the current value of x, y and the stepSize return yCurrent + stepSize * differentialEquation(xCurrent, yCurrent) } export function eulerFull( xStart, xEnd, stepSize, yStart, differentialEquation ) { // loops through all the steps until xEnd is reached, adds a point for each step and then returns all the points const points = [{ x: xStart, y: yStart }] let yCurrent = yStart let xCurrent = xStart while (xCurrent < xEnd) { // Euler method for next step yCurrent = eulerStep(xCurrent, stepSize, yCurrent, differentialEquation) xCurrent += stepSize points.push({ x: xCurrent, y: yCurrent }) } return points } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |