bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / integrate / _ivp / rk / RK23
class
scipy.integrate._ivp.rk:RK23
source: build-install/usr/lib/python3.14/site-packages/scipy/integrate/_ivp/rk.py:183
Signature
class RK23(fun, t0, y0, t_bound, max_step = inf, rtol = 0.001, atol = 1e-06, vectorized = False, first_step = None, **extraneous)Summary
Explicit Runge-Kutta method of order 3(2).
Extended Summary
This uses the Bogacki-Shampine pair of formulas [1]. The error is controlled assuming accuracy of the second-order method, but steps are taken using the third-order accurate formula (local extrapolation is done). A cubic Hermite polynomial is used for the dense output.
Can be applied in the complex domain.
Parameters
fun: callableRight-hand side of the system: the time derivative of the state
yat timet. The calling signature isfun(t, y), wheretis a scalar andyis an ndarray withlen(y) = len(y0).funmust return an array of the same shape asy. Seevectorizedfor more information.t0: floatInitial time.
y0: array_like, shape (n,)Initial state.
t_bound: floatBoundary time - the integration won't continue beyond it. It also determines the direction of the integration.
max_step: float, optionalMaximum allowed step size. Default is np.inf, i.e., the step size is not bounded and determined solely by the solver.
rtol, atol: float and array_like, optionalRelative and absolute tolerances. The solver keeps the local error estimates less than
atol + rtol * abs(y). Herertolcontrols a relative accuracy (number of correct digits), whileatolcontrols absolute accuracy (number of correct decimal places). To achieve the desiredrtol, setatolto be smaller than the smallest value that can be expected fromrtol * abs(y)so thatrtoldominates the allowable error. Ifatolis larger thanrtol * abs(y)the number of correct digits is not guaranteed. Conversely, to achieve the desiredatolsetrtolsuch thatrtol * abs(y)is always smaller thanatol. If components of y have different scales, it might be beneficial to set differentatolvalues for different components by passing array_like with shape (n,) foratol. Default values are 1e-3 forrtoland 1e-6 foratol.vectorized: bool, optionalWhether
funmay be called in a vectorized fashion. False (default) is recommended for this solver.If
vectorizedis False,funwill always be called withyof shape(n,), wheren = len(y0).If
vectorizedis True,funmay be called withyof shape(n, k), wherekis an integer. In this case,funmust behave such thatfun(t, y)[:, i] == fun(t, y[:, i])(i.e. each column of the returned array is the time derivative of the state corresponding with a column ofy).Setting
vectorized=Trueallows for faster finite difference approximation of the Jacobian by methods 'Radau' and 'BDF', but will result in slower execution for this solver.first_step: float or None, optionalInitial step size. Default is
Nonewhich means that the algorithm should choose.**extraneousAny additional keyword arguments will be ignored.
Attributes
n: intNumber of equations.
status: strCurrent status of the solver: 'running', 'finished' or 'failed'.
t_bound: floatBoundary time.
direction: floatIntegration direction: +1 or -1.
t: floatCurrent time.
y: ndarrayCurrent state.
t_old: floatPrevious time. None if no steps were made yet.
step_size: floatSize of the last successful step. None if no steps were made yet.
nfev: intNumber evaluations of the system's right-hand side.
njev: intNumber of evaluations of the Jacobian. Is always 0 for this solver as it does not use the Jacobian.
nlu: intNumber of LU decompositions. Is always 0 for this solver.
Examples
This example demonstrates how to compute one period of a periodic orbit in a two-dimensional dynamical system.import numpy as np import scipy.integrate as itg import matplotlib.pylab as plt✓
def dynam_sys(t, x): dx1_dt = 5*(1-x[1]**2)*x[0] - x[1] dx2_dt = x[0] return [dx1_dt, dx2_dt]✓
solver = itg.RK45(dynam_sys, 0, [0.25,0.25], 1E200, max_step=0.05)
✓soly = solver.y.reshape(1, 2)
✓for i in range(2000): solver.step() solyn = solver.y.reshape(1, 2) soly = np.concatenate((soly, solyn))✓
plt.plot(soly[:,0], soly[:,1]) plt.plot(soly[0,0], soly[0,1], "go") plt.plot(soly[-1,0], soly[-1,1], "mo")✗
[<matplotlib.lines.Line2D object at 0x7f3f687cae40>]
plt.show()
✓
init = np.array([soly[-1,0], soly[-1,1]]) POsolver = itg.RK23(dynam_sys, 0, init, 5000, max_step=0.05)✓
dist_init = 1 POsoly = POsolver.y.reshape(1, 2) while dist_init > 0.005: POsolver.step() POsolyn = POsolver.y.reshape(1, 2) POsoly = np.concatenate((POsoly, POsolyn)) dist_init = np.linalg.norm(init-POsolyn)✓
plt.plot(POsoly[:,0], POsoly[:,1]) plt.plot(POsoly[0,0], POsoly[0,1], "go") plt.plot(POsoly[-1,0], POsoly[-1,1], "mo")✗
[<matplotlib.lines.Line2D object at 0x7f3f68ed3cb0>]
plt.show()
✓
Aliases
scipy.integrate.RK23