ivp

class quantecon.ivp.IVP(f, jac=None)[source]

Bases: ode

Creates an instance of the IVP class.

Parameters:
fcallable f(t, y, *f_args)

Right hand side of the system of equations defining the ODE. The independent variable, t, is a scalar; y is an ndarray of dependent variables with y.shape == (n,). The function f should return a scalar, ndarray or list (but not a tuple).

jaccallable jac(t, y, *jac_args), optional(default=None)

Jacobian of the right hand side of the system of equations defining the ODE.

Attributes:
y

Methods

compute_residual(traj, ti[, k, ext])

The residual is the difference between the derivative of the B-spline approximation of the solution trajectory and the right-hand side of the original ODE evaluated along the approximated solution trajectory.

get_return_code()

Extracts the return code for the integration to enable better control if the integration fails.

integrate(t[, step, relax])

Find y=y(t), set y as an initial condition, and return y.

interpolate(traj, ti[, k, der, ext])

Parametric B-spline interpolation in N-dimensions.

set_f_params(*args)

Set extra parameters for user-supplied function f.

set_initial_value(y[, t])

Set initial conditions y(t) = y.

set_integrator(name, **integrator_params)

Set integrator by name.

set_jac_params(*args)

Set extra parameters for user-supplied function jac.

set_solout(solout)

Set callable to be called at every successful integration step.

solve(t0, y0[, h, T, g, tol, integrator, ...])

Solve the IVP by integrating the ODE given some initial condition.

successful()

Check if integration was successful.

compute_residual(traj, ti, k=3, ext=2)[source]

The residual is the difference between the derivative of the B-spline approximation of the solution trajectory and the right-hand side of the original ODE evaluated along the approximated solution trajectory.

Parameters:
trajarray_like (float)

Solution trajectory providing the data points for constructing the B-spline representation.

tiarray_like (float)

Array of values for the independent variable at which to interpolate the value of the B-spline.

kint, optional(default=3)

Degree of the desired B-spline. Degree must satisfy \(1 \le k \le 5\).

extint, optional(default=2)

Controls the value of returned elements for outside the original knot sequence provided by traj. For extrapolation, set ext=0; ext=1 returns zero; ext=2 raises a ValueError.

Returns:
residualarray (float)

Difference between the derivative of the B-spline approximation of the solution trajectory and the right-hand side of the ODE evaluated along the approximated solution trajectory.

interpolate(traj, ti, k=3, der=0, ext=2)[source]

Parametric B-spline interpolation in N-dimensions.

Parameters:
trajarray_like (float)

Solution trajectory providing the data points for constructing the B-spline representation.

tiarray_like (float)

Array of values for the independent variable at which to interpolate the value of the B-spline.

kint, optional(default=3)

Degree of the desired B-spline. Degree must satisfy \(1 \le k \le 5\).

derint, optional(default=0)

The order of derivative of the spline to compute (must be less than or equal to k).

extint, optional(default=2) Controls the value of returned elements

for outside the original knot sequence provided by traj. For extrapolation, set ext=0; ext=1 returns zero; ext=2 raises a ValueError.

Returns:
interp_traj: ndarray (float)

The interpolated trajectory.

solve(t0, y0, h=1.0, T=None, g=None, tol=None, integrator='dopri5', step=False, relax=False, **kwargs)[source]

Solve the IVP by integrating the ODE given some initial condition.

Parameters:
t0float

Initial condition for the independent variable.

y0array_like (float, shape=(n,))

Initial condition for the dependent variables.

hfloat, optional(default=1.0)

Step-size for computing the solution. Can be positive or negative depending on the desired direction of integration.

Tint, optional(default=None)

Terminal value for the independent variable. One of either T or g must be specified.

gcallable g(t, y, f_args), optional(default=None)

Provides a stopping condition for the integration. If specified user must also specify a stopping tolerance, tol.

tolfloat, optional (default=None)

Stopping tolerance for the integration. Only required if g is also specifed.

integratorstr, optional(default=’dopri5’)

Must be one of ‘vode’, ‘lsoda’, ‘dopri5’, or ‘dop853’

stepbool, optional(default=False)

Allows access to internal steps for those solvers that use adaptive step size routines. Currently only ‘vode’, ‘zvode’, and ‘lsoda’ support step=True.

relaxbool, optional(default=False)

Currently only ‘vode’, ‘zvode’, and ‘lsoda’ support relax=True.

**kwargsdict, optional(default=None)

Dictionary of integrator specific keyword arguments. See the Notes section of the docstring for scipy.integrate.ode for a complete description of solver specific keyword arguments.

Returns:
solution: ndarray (float)

Simulated solution trajectory.