Pendulum – ODE23, ODE45

function wd = pend(t,w);
% This m-file describes the motion of a pendulum subject to gravity,
% in the form required by ODE23 and ODE45.
% The states are:
% w(1)                  the angle theta
% w(2)                  its derivative

l =0.5;                 % length of the pendulum
g=9.81;                 % gravity, m/s/s
wd   =zeros(m,n);       % allocate space for wd
wd(1) = w(2);
wd(2) = -g*l*sin(w(1));