%This is a short script for solving an odesystem and plotting some results.
%
% By default, the ODE solvers in matlab have relatively large error
% tolerance.  I usually find that I want smaller errors than the defaults
% There are many options to the ode solvers that can be adjusted.  Tow
% control the relative and absolute error tolerance.  Here are some good
% starting values to use.
options=odeset('RelTol',1.e-7,'AbsTol',1.e-12);
% There are several solvers available in matlab.  A good general pupose one
% to start with is ode45 (it uses an adaptive step 4th/5th order
% Runge-Kutta method.) In this form the outputs are the independent
% variable t, and an array holding the dependent variables values at those
% times.  Explore the shape and size of t and of y.  IN this case teh
% firrst entrries will be theta, and the seconds will be dtheta/dt.  
% The first argument of ode45 is the funtion that will return the right
% hand side of the ode system.  It is preceded by the @ sign to let Matlab
% know it is a funtion.  The second argument is the time span.  In this
% case we specify a starting time value and an ending one.  The third
% argument is the initial value of the dependent variables, We have
% theta(0)=pi, and dtheta/dt(0)=0/01.  The fourth argument is the options
% as set by the call to odeset, and the last argument is a parameter (in
% this case the value of alpha,0,  that will be passed on to the rhs function.
[t,y]=ode45(@DampedPendulumSystem, [0,30], [pi;0.01],options,0.0)
% This command will generate a plot with theta on the horizonatal axis, and
% dtheta/dt on the vertical axis. Use the help to learn how to make a
% prettier plot with labels etc.
plot(y(:,1),y(:,2))
% This command will repaeat the call to the solver with alpha=0.1.
[t,y]=ode45(@DampedPendulumSystem, [0,30], [pi;.01],options,0.1)
% Plot that result
plot(y(:,1),y(:,2))
xlabel('\theta')
ylabel('d\theta/dt')
title('\alpha=0.1')
% You can save plots from the plot window using save as from the file menu
% and choosing a pdf or jpeg file or bmp or ..., and then include these in
% other documents.