% pset3_3.m
% Solving the equation for one mass and one spring
% Please replace question marks by appropriate code

T=2*pi; % final time
n=2^3-1;
dt=T/(n+1); % time step

u=zeros(1,n+2);
v=u; % v is u'

u(1)=1; % initial condition, u(t=0)=1
v(1)=0; % initial condition, v(t=0)=0

for j=1:n+1
    u(j+1)=u(j)+dt*???; % advance u by one time step
    v(j+1)=v(j)+dt*???; % advance v by one time step
end

disp(sqrt((u(n+2)-u(1))^2+(v(n+2)-v(1))^2)); % error at final t=T

% plot phase plane
plot(u,v,'-o'); axis equal; axis tight; grid on
xlabel('u');ylabel('v');
