# brainpy.integrators.fde.CaputoEuler#

class brainpy.integrators.fde.CaputoEuler(f, alpha, num_memory, inits, dt=None, name=None, state_delays=None)[source]#

One-step Euler method for Caputo fractional differential equations.

Given a fractional initial value problem,

$D_{*}^{\alpha} y(t)=f(t, y(t)), \quad y^{(k)}(0)=y_{0}^{(k)}, \quad k=0,1, \ldots,\lceil\alpha\rceil-1$

where the $$y_0^{(k)}$$ ay be arbitrary real numbers and where $$\alpha>0$$. $$D_{*}^{\alpha}$$ denotes the differential operator in the sense of Caputo, defined by

$D_{*}^{\alpha} z(t)=J^{n-\alpha} D^{n} z(t)$

where $$n:=\lceil\alpha\rceil$$ is the smallest integer $$\geqslant \alpha$$, Here $$D^n$$ is the usual differential operator of (integer) order $$n$$, and for $$\mu > 0$$, $$J^{\mu}$$ is the Riemann–Liouville integral operator of order $$\mu$$, defined by

$J^{\mu} z(t)=\frac{1}{\Gamma(\mu)} \int_{0}^{t}(t-u)^{\mu-1} z(u) \mathrm{d} u$

The one-step Euler method for fractional differential equation is defined as

$y_{k+1} = y_0 + \frac{1}{\Gamma(\alpha)} \sum_{j=0}^{k} b_{j, k+1} f\left(t_{j}, y_{j}\right).$

where

$b_{j, k+1}=\frac{h^{\alpha}}{\alpha}\left((k+1-j)^{\alpha}-(k-j)^{\alpha}\right).$

Examples

>>> import brainpy as bp
>>>
>>> a, b, c = 10, 28, 8 / 3
>>> def lorenz(x, y, z, t):
>>>   dx = a * (y - x)
>>>   dy = x * (b - z) - y
>>>   dz = x * y - c * z
>>>   return dx, dy, dz
>>>
>>> duration = 30.
>>> dt = 0.005
>>> inits = [1., 0., 1.]
>>> f = bp.fde.CaputoEuler(lorenz, alpha=0.97, num_memory=int(duration / dt), inits=inits)
>>> runner = bp.integrators.IntegratorRunner(f, monitors=list('xyz'), dt=dt, inits=inits)
>>> runner.run(duration)
>>>
>>> import matplotlib.pyplot as plt
>>> plt.plot(runner.mon.x.flatten(), runner.mon.z.flatten())
>>> plt.show()

Parameters:
• f (callable) – The derivative function.

• alpha (int, float, jnp.ndarray, bm.ndarray, sequence) – The fractional-order of the derivative function. Should be in the range of (0., 1.).

• num_memory (int) – The total time step of the simulation.

• inits (sequence) – A sequence of the initial values for variables.

• dt (float, int) – The numerical precision.

• name (str) – The integrator name.

References

__init__(f, alpha, num_memory, inits, dt=None, name=None, state_delays=None)[source]#

Methods

 __init__(f, alpha, num_memory, inits[, dt, ...]) 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

 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. parameters The parameters defined in the differential equation. state_delays State delays. variables The variables defined in the differential equation.