%% Evaluate and Extend Solution Structure
% The van der Pol equation is a second order ODE
% y''_1 - \mu \left( 1 - y_1^2\right) y'_1+y_1=0.
% Solve the van der Pol equation with \mu = 1 using ode45. The function vdp1.m ships with MATLAB® and encodes the equations. Specify a single output to return a structure containing information about the solution, such as the solver and evaluation points.

tspan = [0 20];
y0 = [2 0];
sol = ode45(@vdp1,tspan,y0)

%
% Use linspace to generate 250 points in the interval [0 20]. Evaluate the solution at these points using deval.

x = linspace(0,20,250);
y = deval(sol,x);

%
% Plot the first component of the solution.

plot(x,y(1,:))

%
% Extend the solution to t_f = 35 using odextend and add the result to the original plot.

sol_new = odextend(sol,@vdp1,35);
x = linspace(20,35,350);
y = deval(sol_new,x);
hold on
plot(x,y(1,:),'r')

% Copyright 2012 The MathWorks, Inc.