Integration and ODEs
Methods
====================================================== ============================== Method Description ====================================================== ============================== solveIvp_ (fun, t0, t_bound, y0, method, atol, rtol) Solve initial value problem ====================================================== ==============================
Description
.. _solveIvp:
.. function:: solveIvp(fun, t0, t_bound, y0, method, atol, rtol)
:param fun: (Float64, Array<Float64>, Int64) -> Float64, specifies the ODE
:param t0: initial time
:param t_bound: maximum time for solving ODE
:param y0: initial state
:param method: method for solving ODE, ``rk45`` or ``rk23``
:param atol: absolute error tolerance (currently unused)
:param rtol: relative error tolerance (currently unused)
:return: (Vector<Float64>, Array<Vector<Float64>>)
Solve initial value problem. Currently implements Runge-Kutta method (RK45 and RK23).
Example:
1. Solve the ODE :math:`y'(t) = y^2(t)\cos(t+y(t))`.
::
func fun3(x: Float64, y: Array<Float64>, j: Int64): Float64 {
return y[0] * y[0] * cos(x + y[0])
}
var (vec_x, vec_y) = solveIvp(
fun3, 0.0, 100.0, Array<Float64>([0.2]), "rk45", 1e-3, 1e-6)
plot(vec_x, vec_y[0])
xlabel("t")
ylabel("y(t)")
title("Solution to ODE y'=y^2cos(t+y)")
Result:
.. image:: ../../tests/imgs/ode/rk_45.png
:align: center
:width: 480