ivp

Base class for solving initial value problems (IVPs) of the form:

\[\frac{dy}{dt} = f(t,y),\ y(t_0) = y_0\]

using finite difference methods. The quantecon.ivp class uses various integrators from the scipy.integrate.ode module to perform the integration (i.e., solve the ODE) and parametric B-spline interpolation from scipy.interpolate to approximate the value of the solution between grid points. The quantecon.ivp module also provides a method for computing the residual of the solution which can be used for assessing the overall accuracy of the approximated solution.

@author : David R. Pugh @date : 2014-09-09

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

Bases: scipy.integrate._ode.ode

Creates an instance of the IVP class.

Parameters:

f : callable 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).

jac : callable 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.
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:

traj : array_like (float)

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

ti : array_like (float)

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

k : int, optional(default=3)

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

ext : int, 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:

residual : array (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:

traj : array_like (float)

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

ti : array_like (float)

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

k : int, optional(default=3)

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

der : int, optional(default=0)

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

ext : int, 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:

t0 : float

Initial condition for the independent variable.

y0 : array_like (float, shape=(n,))

Initial condition for the dependent variables.

h : float, optional(default=1.0)

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

T : int, optional(default=None)

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

g : callable 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.

tol : float, optional (default=None)

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

integrator : str, optional(default=’dopri5’)

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

step : bool, 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.

relax : bool, optional(default=False)

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

**kwargs : dict, 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.