maths.euler_method

Functions

explicit_euler(→ numpy.ndarray)

Calculate numeric solution at each step to an ODE using Euler's Method

Module Contents

maths.euler_method.explicit_euler(ode_func: collections.abc.Callable, y0: float, x0: float, step_size: float, x_end: float) numpy.ndarray

Calculate numeric solution at each step to an ODE using Euler’s Method

For reference to Euler’s method refer to https://en.wikipedia.org/wiki/Euler_method.

Args:
ode_func (Callable): The ordinary differential equation

as a function of x and y.

y0 (float): The initial value for y. x0 (float): The initial value for x. step_size (float): The increment value for x. x_end (float): The final value of x to be calculated.

Returns:

np.ndarray: Solution of y for every step in 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)
>>> float(y[-1])
144.77277243257308