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 — Python/maths/explicit_euler.py at master · SharathKumarGithub/Python Expand file tree/ Copy pathexplicit_euler.pyMore file actions 40 lines (30 loc) · 894 Bytes / Copy pathexplicit_euler.pyFile metadata and controls40 lines (30 loc) · 894 Bytes 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 37 38 39 40 import numpy as np def explicit_euler(ode_func, y0, x0, stepsize, x_end): """ Calculate numeric solution at each step to an ODE using Euler's Method https://en.wikipedia.org/wiki/Euler_method Arguments: ode_func -- The ode as a function of x and y y0 -- the initial value for y x0 -- the initial value for x stepsize -- the increment value for x x_end -- the end value for x >>> # the exact solution is math.exp(x) >>> def f(x, y): ... return y >>> y0 = 1 >>> y = explicit_euler(f, y0, 0.0, 0.01, 5) >>> y[-1] 144.77277243257308 """ N = int(np.ceil((x_end - x0) / stepsize)) y = np.zeros((N + 1,)) y[0] = y0 x = x0 for k in range(N): y[k + 1] = y[k] + stepsize * ode_func(x, y[k]) x += stepsize return y if __name__ == "__main__": import doctest doctest.testmod() |
| You are visitor 01402792 — 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. |