# brainpy.integrators.ode.explicit_rk.Euler#

class brainpy.integrators.ode.explicit_rk.Euler(f, var_type=None, dt=None, name=None, show_code=False, state_delays=None, neutral_delays=None)[source]#

The Euler method for ODEs.

Also named as Forward Euler method, or Explicit Euler method.

Given an ODE system,

$y'(t)=f(t,y(t)),\qquad y(t_{0})=y_{0},$

by using Euler method 1, we should choose a value $$h$$ for the size of every step and set $$t_{n}=t_{0}+nh$$. Now, one step of the Euler method from $$t_{n}$$ to $$t_{n+1}=t_{n}+h$$ is:

$y_{n+1}=y_{n}+hf(t_{n},y_{n}).$

Note that the method increments a solution through an interval $$h$$ while using derivative information from only the beginning of the interval. As a result, the step’s error is $$O(h^2)$$.

Geometric interpretation

Illustration of the Euler method. The unknown curve is in blue, and its polygonal approximation is in red 2:

Derivation

There are several ways to get Euler method 2.

The first is to consider the Taylor expansion of the function $$y$$ around $$t_{0}$$:

$y(t_{0}+h)=y(t_{0})+hy'(t_{0})+{\frac {1}{2}}h^{2}y''(t_{0})+O(h^{3}).$

where $$y'(t_0)=f(t_0,y)$$. We ignore the quadratic and higher-order terms, then we get Euler method. The Taylor expansion is used below to analyze the error committed by the Euler method, and it can be extended to produce Runge–Kutta methods.

The second way is to replace the derivative with the forward finite difference formula:

$y'(t_{0})\approx {\frac {y(t_{0}+h)-y(t_{0})}{h}}.$

The third method is integrate the differential equation from $$t_{0}$$ to $$t_{0}+h$$ and apply the fundamental theorem of calculus to get:

$y(t_{0}+h)-y(t_{0})=\int _{t_{0}}^{t_{0}+h}f(t,y(t))\,\mathrm {d} t \approx hf(t_{0},y(t_{0})).$

Note

Euler method is a first order numerical procedure for solving ODEs with a given initial value. The lack of stability and accuracy limits its popularity mainly to use as a simple introductory example of a numeric solution method.

References

1

W. H.; Flannery, B. P.; Teukolsky, S. A.; and Vetterling, W. T. Numerical Recipes in FORTRAN: The Art of Scientific Computing, 2nd ed. Cambridge, England: Cambridge University Press, p. 710, 1992.

2(1,2)

https://en.wikipedia.org/wiki/Euler_method

__init__(f, var_type=None, dt=None, name=None, show_code=False, state_delays=None, neutral_delays=None)#

Methods

 __init__(f[, var_type, dt, name, show_code, ...]) build() load_states(filename[, verbose]) Load the model states. nodes([method, level, include_self]) Collect all children nodes. register_implicit_nodes(nodes) register_implicit_vars(variables) save_states(filename[, variables]) Save the model states. set_integral(f) Set the integral function. train_vars([method, level, include_self]) The shortcut for retrieving all trainable variables. unique_name([name, type_]) Get the unique name for this object. vars([method, level, include_self]) Collect all variables in this node and the children nodes.

Attributes

 A B C arg_names arguments All arguments when calling the numer integrator of the differential equation. dt The numerical integration precision. integral The integral function. name neutral_delays neutral delays. parameters The parameters defined in the differential equation. state_delays State delays. variables The variables defined in the differential equation.