Consider the following Lorenz system of ODEs
\begin{equation}\label{eq:lorenz}
\boldsymbol y'(x) = \begin{bmatrix}
y_1'\newline
y_2'\newline
y_3
\end{bmatrix} =
\begin{bmatrix}
-\alpha y_1+\alpha y_2, \newline
-y_1y_3+\beta y_1- y_2, \newline
y_1y_2-\gamma y_3.
\end{bmatrix} =
\begin{bmatrix}
f_1(x,y_1,y_2,y_3)\newline
f_2(x,y_1,y_2,y_3)\newline
f_3(x,y_1,y_2,y_3)
\end{bmatrix} =
\boldsymbol f(x,\boldsymbol y)
\end{equation}
function [t, y] = RK6IMPL(FUNC, x0, xN, y0, N, var)
% RK6IMPL Runge-Kutta-Algorithm
% Executes the implicit Runge-Kutta-Algorithm of Kuntzmann
% and Butcher to solve a system of differential equations
% of first order defined in by 'FUNC'.
% FUNC : Ordinary differential equation
% x0 : starting x
% xN : end x
% y0 : initial value
% N : number of x intervalls
% var : Function arguments passed to the ode file
%
% Butcher-Scheme of the implemented Runge-Kutta-Method:
% 1/2-\sqrt{15}/10 | 5/36 2/9-\sqrt{15}/15 5/36-\sqrt{15}/30
% 1/2 | 5/36+\sqrt{15}/24 2/9 5/36-\sqrt{15}/24
% 1/2+\sqrt{15}/10 | 5/36+\sqrt{15}/30 2/9+\sqrt{15}/15 5/36
% ---------------------------------------------------------------------------
% | 5/18 4/9 5/18
%
tol = 10e-6;
MAXSTEP = 500;
% Computation of the coefficients
alpha =[ 0.5-sqrt(15)/10; 0.5; 0.5+sqrt(15)/10];
beta = [ 5/36, 2/9-sqrt(15)/15, 5/36-sqrt(15)/30;...
5/36+sqrt(15)/24, 2/9, 5/36-sqrt(15)/24;...
5/36+sqrt(15)/30, 2/9+sqrt(15)/15, 5/36];
gamma = [5/18, 4/9, 5/18];
h = (tN-t0)/N;
t(1) = t0;
y(:,1) = y0;
for i=1:N
t(i+1) = t0 + i*h;
% Initialization of k and l
knew = zeros(length(y0),3);
kold = ones(length(y0),3);
l = 0;
% Computation of k
while (norm([knew(:,1);knew(:,2);knew(:,3)]...
-[kold(:,1);kold(:,2);kold(:,3)]) > tol) & (l < MAXSTEP)
kold = knew;
knew(:,1) = feval(FUNC, t(i)+h*alpha(1),...
y(:,i)+h*(beta(1,1)*kold(:,1)+beta(1,2)*kold(:,2)...
+beta(1,3)*kold(:,3)), var);
knew(:,2) = feval(FUNC, t(i)+h*alpha(2),...
y(:,i)+h*(beta(2,1)*kold(:,1)+beta(2,2)*kold(:,2)...
+beta(2,3)*kold(:,3)), var);
knew(:,3) = feval(FUNC, t(i)+h*alpha(3),...
y(:,i)+h*(beta(3,1) * kold(:,1)+beta(3,2)*kold(:,2)...
+beta(3,3)* kold(:,3)), var);
l = l+1;
end
% compute y_{i+1}
y(:,i+1) = y(:,i) + h * knew * gamma;
end