# brainpy.integrators.ode.Euler#

class brainpy.integrators.ode.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 , 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 : Derivation

There are several ways to get Euler method .

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

__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() cpu() Move all variable into the CPU device. cuda() Move all variables into the GPU device. load_state_dict(state_dict[, warn, compatible]) Copy parameters and buffers from state_dict into this module and its descendants. load_states(filename[, verbose]) Load the model states. nodes([method, level, include_self]) Collect all children nodes. register_implicit_nodes(*nodes[, node_cls]) register_implicit_vars(*variables[, var_cls]) save_states(filename[, variables]) Save the model states. set_integral(f) Set the integral function. state_dict() Returns a dictionary containing a whole state of the module. to(device) Moves all variables into the given device. tpu() Move all variables into the TPU device. train_vars([method, level, include_self]) The shortcut for retrieving all trainable variables. tree_flatten() Flattens the object as a PyTree. tree_unflatten(aux, dynamic_values) Unflatten the data to construct an object of this class. 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 arguments All arguments when calling the numer integrator of the differential equation. dt The numerical integration precision. integral The integral function. name Name of the model. neutral_delays neutral delays. parameters The parameters defined in the differential equation. state_delays State delays. variables The variables defined in the differential equation.