nutopy.ivp.exp

exp(f, tf, t0, x0, pars=None, *, options=None, time_steps=None, dfdx=None, args=(), kwargs={})[source]

The exp function computes a numerical approximation of the solution of the initial value problem

\[\frac{d}{d t} x = \dot{x} = f(t, x, pars), \quad x(t_0) = x_0,\]

where \(pars \in \mathbf{R}^k\) is a vector of parameters, \(t\) is the time and \(x\) is the state variable. The time \(t_0\) is refered as the initial time, \(x_0\) as the initial condition and \(f\) as the dynamics. The solution of the initial value problem at the final time \(t_f\) is denoted \(x(t_f, t_0, x_0, pars)\).

Parameters
  • f (callable) – A vector function representing the dynamics: f(t, x) or f(t, x, pars)

  • tf (float) – Final time

  • t0 (float) – Initial time

  • x0 (float vector) – Initial condition

  • pars (float vector, optional, positional) – If pars is None then provide f(t,x) else f(t,x,pars).

  • options (nutopy.ivp.Options, optional, key only) – A dictionnary of solver options. The integrator scheme is chosen setting SolverMethod.

  • time_steps (float vector, optional, key only) –

    If time_steps is not None, then it is a vector of time steps, that is sol.tout = time_steps. If time_steps is None, then sol.tout = [t0, tf] if a fixed-step integrator scheme is used while sol.tout is given by the integrator if a variable step-size scheme is used.

    Remark. Note that in the case of a variable step-size integrator scheme, time_steps is used only for output, that is the steps are computed by the integrator but dense output is used to provide by interpolation the solution x at times in time_steps.

  • dfdx (callable, optional, key only) –

    a vector function dfdx(t, x, dx) or dfdx(t, x, dx, pars) if pars is not None, computing

    \[\frac{\partial f}{\partial x}(t, x, pars) \cdot dx,\]

    where dx is a float vector of the same dimension as x.

    Remark. dfdx is used only if SolverMethod is an implicit Runge-Kutta scheme.

  • args (tuple, key only) – optional arguments for f (and dfdx if provided)

  • kwargs (dictionnary, key only) – keywords optional arguments for f (and dfdx if provided)

Returns

sol – A dictionary/struct of outputs:

  • sol.xf or sol.get('xf') : final point x(tf, t0, x0, pars);

  • sol.tout : the integration time-steps: tout=time_steps if provided;

  • sol.xout : the integration points: xout[i] = x(tout[i], t0, x0, pars);

  • sol.success : whether or not the integrator exited successfully;

  • sol.status : termination status of the integrator;

  • sol.message : description of the cause of the termination;

  • sol.nfev : number of evaluations of the dynamics;

  • sol.nsteps : number of integration time-steps.

Notes

Use numpy.ndarray to define float vectors.

Examples

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from nutopy import ivp
>>> def f(t, x):
...     dx = np.zeros(x.size)
...     dx[0] = -x[0] + x[1]
...     dx[1] = x[1]
...     return dx
>>> x0 = np.array([-1.0, 1.0])
>>> t0 = 0.0
>>> tf = 1.0
>>> sol = ivp.exp(f, tf, t0, x0)
>>> print(sol.xf)
[0.80732175 2.71828183]
>>> plt.plot(sol.tout, sol.xout[:,0], 'b', sol.tout, sol.xout[:,1], 'r')
>>> plt.show()

(Source code)

Raises