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 thetime
and \(x\) is thestate
variable. The time \(t_0\) is refered as theinitial time
, \(x_0\) as theinitial condition
and \(f\) as thedynamics
. The solution of the initial value problem at thefinal 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)
orf(t, x, pars)
tf (
float
) – Final timet0 (
float
) – Initial timex0 (float vector) – Initial condition
pars (float vector, optional, positional) – If
pars
isNone
then providef(t,x)
elsef(t,x,pars)
.options (
nutopy.ivp.Options
, optional, key only) – A dictionnary of solver options. The integrator scheme is chosen settingSolverMethod
.time_steps (float vector, optional, key only) –
If
time_steps
is notNone
, then it is a vector of time steps, that issol.tout = time_steps
. Iftime_steps
isNone
, thensol.tout = [t0, tf]
if a fixed-step integrator scheme is used whilesol.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 intime_steps
.dfdx (callable, optional, key only) –
a vector function
dfdx(t, x, dx)
ordfdx(t, x, dx, pars)
ifpars
is notNone
, computing\[\frac{\partial f}{\partial x}(t, x, pars) \cdot dx,\]where
dx
is a float vector of the same dimension asx
.Remark.
dfdx
is used only ifSolverMethod
is an implicit Runge-Kutta scheme.args (tuple, key only) – optional arguments for
f
(anddfdx
if provided)kwargs (dictionnary, key only) – keywords optional arguments for
f
(anddfdx
if provided)
- Returns
sol – A dictionary/struct of outputs:
sol.xf
orsol.get('xf')
: final pointx(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()
- Raises
ArgumentTypeError – Variable tf must be a float or cast to float.
ArgumentTypeError – Variable t0 must be a float or cast to float.
ArgumentTypeError – Variable options must be a Options object.
ArgumentDimensionError – Variable x0 must be a one dimensional array.
ArgumentDimensionError – Variable pars must be a one dimensional array.
InputArgumentError – You must have time_steps[0]=t0 and time_steps[-1]=tf.
InputArgumentError – The argument time_steps cannot be of size 1.