%  Example of the use of Rke and Yvalue.
%  REQUIRES Rke.m, Yvalue.m, and X2rkef.m.

%  Set initial values and tolerances.

y = [1; 1];
h = 0.1;
tol = 1e-5;
threshold = [1e-5; 1e-5];

%  Define the solution output points.
nout = 11;
xout = 0:(nout-1);
    
%  Integration loop: call Rke and Yvalue as necessary.
x = xout(1);
nasteps = 0;
k0 = zeros(2,1);
for i = 1:nout
  while x <= xout(i)
    [x,y,k0,h,flag,step,ycoeff,nasteps] = ...
      Rke('X2rkef',x,y,k0,h,tol,threshold,nasteps);
    if flag ~= 0
      error(['flag = ',int2str(flag),' at x = ',num2str(x),'.']);
    end
  end

  z = Yvalue(xout(i),x,step,ycoeff);
  fprintf('Xout = %6.2f   Y(1) = %10.6f   Y(2) = %10.6f\n', ...
           xout(i),z(1),z(2));
end
