# perturbsolve_ivp¶

probnum.diffeq.perturbsolve_ivp(f, t0, tmax, y0, rng, method='RK45', perturb='step-lognormal', noise_scale=10.0, adaptive=True, atol=1e-06, rtol=0.001, step=None, time_stops=None)[source]

Solve an initial value problem with a perturbation-based ODE solver.

Parameters
Raises
• ValueError – If the ‘method’ string does not correspond to a supported method.

• ValueError – If the ‘perturb’ string does not correspond to a supported perturbation style.

Returns

ODE Solution of the perturbed-step-solver.

Return type

perturbed.step.PerturbedStepSolution

Examples

```>>> from probnum.diffeq import perturbsolve_ivp
>>> import numpy as np
```

Solve a simple logistic ODE with fixed steps. Per default, perturbsolve_ivp uses a perturbed-step solver with lognormal perturbation.

```>>> rng = np.random.default_rng(seed=2)
>>>
>>> def f(t, x):
...     return 4*x*(1-x)
>>>
>>> y0 = np.array([0.15])
>>> t0, tmax = 0., 1.5
>>> solution = perturbsolve_ivp(
...     f, t0, tmax, y0, rng=rng, step=0.25, method="RK23", adaptive=False
... )
>>> print(np.round(solution.states.mean, 3))
[[0.15 ]
[0.325]
[0.56 ]
[0.772]
[0.893]
[0.964]
[0.989]]
```

Each solution is the result of a randomly-perturbed call of an underlying Runge-Kutta solver. Therefore, if you call it again, the output will be different:

```>>> other_solution = perturbsolve_ivp(
...     f, t0, tmax, y0, rng=rng, step=0.25, method="RK23", adaptive=False
... )
>>> print(np.round(other_solution.states.mean, 3))
[[0.15 ]
[0.319]
[0.57 ]
[0.785]
[0.908]
[0.968]
[0.989]]
```

Other methods, such as RK45 (as well as other perturbation styles) are easily accessible. Let us solve the same equation, with an adaptive RK45 solver that uses uniformly perturbed steps.

```>>> solution = perturbsolve_ivp(
...     f, t0, tmax, y0, rng=rng, atol=1e-5, rtol=1e-6,
... )
>>> print(np.round(solution.states.mean, 3))
[[0.15 ]
[0.152]
[0.167]
[0.26 ]
[0.431]
[0.646]
[0.849]
[0.883]
[0.915]
[0.953]
[0.976]
[0.986]]
```

References

1(1,2)

Abdulle, A. and Garegnani, G.. Random time step probabilistic methods for uncertainty quantification in chaotic and geometric numerical integration. Statistics and Computing. 2020.

2

J. R. Dormand, P. J. Prince.. A family of embedded Runge-Kutta formulae. Journal of Computational and Applied Mathematics, Vol. 6, No. 1, pp. 19-26, 1980.

3

L. W. Shampine. Some Practical Runge-Kutta Formulas. Mathematics of Computation, Vol. 46, No. 173, pp. 135-150, 1986.

4

P. Bogacki, L.F. Shampine. A 3(2) Pair of Runge-Kutta Formulas. Appl. Math. Lett. Vol. 2, No. 4. pp. 321-325, 1989.