%
% Example of ODE solver of MATLAB
%

% set some option for the ODE numerical solver
options = odeset('RelTol',1e-7,'AbsTol',[1e-7 1e-7 1e-7]);

% se initial condition for the problem
Y0 = [ -7.5 -3.6 30 ] ;

% Set a vector specifying the interval of integration, [t0,tf].
% The solver imposes the initial conditions at TSPAN(1),
% and integrates from TSPAN(1) to TSPAN(end). 
% To obtain solutions at specific times (all increasing or all decreasing), 
% use TSPAN = [t0,t1,...,tf].
TSPAN = [ 0:0.01:10 ] ;

% load the "pointer" of the function to FUN
FUN = @lorenz ;

% Runge-Kutta embedded of order 2 and 3 by Bogaci and Shampine
[T1,Y1] = ode23 ( FUN, TSPAN, Y0, options ) ;

% Runge-Kutta embedded of order 4 and 5 by Dormand and Prince (first choice scheme)
[T2,Y2] = ode45 ( FUN, TSPAN, Y0, options ) ;

% Adams-bashforth-Moulton PECE
[T3,Y3] = ode113 ( FUN, TSPAN, Y0, options ) ;

% Numerical Differentiation Formula, similar to Backward Differetiation Formula
% by Gear. Useful for stiff problem.
[T4,Y4] = ode15s ( FUN, TSPAN, Y0, options ) ;

% Rosenbrock of order 2. For stiff problem.
[T5,Y5] = ode23s ( FUN, TSPAN, Y0, options ) ;

% Trapeziodal rule for moderately stiff problem
[T6,Y6] = ode23t ( FUN, TSPAN, Y0, options ) ;

% TR-BDF2 an implit Runge-Kutta where the first stage is the 
% trapezoidal rule and teh second stage is a BDF formula of order 2
[T7,Y7] = ode23tb ( FUN, TSPAN, Y0, options ) ;

%
% plot the functions approximated by various solver
%
plot( T1, Y1(:,1), 'r-',  ...
      T2, Y2(:,1), 'g--', ...
      T3, Y3(:,1), 'b:',  ...
      T4, Y4(:,1), 'c-.', ...
      T5, Y5(:,1), 'm--',  ...
      T6, Y6(:,1), 'y:',  ...
      T7, Y7(:,1), 'k-.' )
