%
% This MATLAB script provides an example of
% using MATLAB's ODE solver and plotting the
% results.  It uses the vector field defined
% in vanderpol.m.
%

%
% Set the parameter values, and put them
% into the vector p.
%
a = 0;
epsilon = 0.001;
p = [a; epsilon];

%
% Set the initial conditions, and put them
% into the vector v0.
%
x0 = 0;
y0 = -1.2;
v0 = [x0; y0];

%
% T is the time duration for the solution.
%
T = 5.0;

%
% Set some error tolerances for the ODE solver.
%
opts = odeset('RelTol',1e-4,'AbsTol',1e-7);

%
% Call the ODE solver.
% (Compare the behavior of ode45 to that of ode15s
% when epsilon is small.)
%
[t,v] = ode45(@vanderpol,[0 T],v0,opts,p);

%
% Plot the results.
% Make two plots.  One is the phase plane,
% and the other will have two subplots,
% one for x(t) and one for y(t).
%

figure(1)
clf
plot(v(:,1),v(:,2))
xlabel('x')
ylabel('y')

figure(2)
clf
subplot(2,1,1)
plot(t,v(:,1))
xlabel('t')
ylabel('x')
subplot(2,1,2)
plot(t,v(:,2))
xlabel('t')
ylabel('y')
