rkfixed(init, x1, x2, npoints, D) Fourth-order
Runge-Kutta fixed-step method is used.
Rkadapt(init, x1, x2, npoints, D) Fourth-order Runge-Kutta with adaptive
step-size.
Bulstoer(init, x1, x2, npoints, D) Bulirsch-Stoer method is used, which
is slightly more accurate than Runge-Kutta, but requires a smoothly varying
system.
Each of these functions returns a matrix in which the first column contains
the npoints between x1
and x2 at which the solution to the ODE is evaluated.
Subsequent columns contain the corresponding values of the solution(s)
to the nth-order ODE(s) and the n
− 1 derivatives of the solution(s). Either a single ODE or a system of
ODE equations are allowed.
Arguments:
init is either a
vector of n real initial values or a single scalar
initial value, in the case of a single ODE.
x1 and x2
are real, scalar endpoints of the interval over which the solution to
the ODE(s) will be evaluated. Initial values in init
are the values of the ODE function(s) evaluated at x1.
npoints is the integer number
of points beyond the initial point at which the solution is to be approximated.
This determines the number of rows (1 + npoints)
in the matrix of solutions.
D(x,y) is
an n-element vector-valued function of the independent
variable, x, and a vector of functions, y,
containing the equations for the first derivatives of all unknown
functions in the system of ODEs. To create this vector, cast your equation(s)
with a first derivative term by itself on the left-hand-side, with no
multipliers, and no higher order derivatives in the equation. For example,
a single ODE of the function y(x) which contains
a second derivative must be written as a system of equations in y0(x) and y1(x),
where the first derivative of y0 is
y1. The single-function ODE
The vector of functions, D, is specified without its argument
list to the ODE solvers, and the functions yn(x)
are specified in D without their argument. The second argument
to D must be subscripted as a vector, even if there is only
a single entry.
Rkadapt uses non-uniform step sizes internally when it solves
the differential equation, adding more steps in regions of greater variation
of the solution, but returns the solution at the number of equally spaced
points specified in npoints.
You may wish to use ODE Solve Blocks to simplify
the entry of your equations and initial conditions.