%Problem Set on ODE # 2

%We consider the ODE
%   u'=du/dt=Au+f
%
%The eigenvalues are obtained for the matrix A where
A=[-10,-0.1,-0.1;      
    1,-1,1;                
    10,1,-1];          

f=[-1;
    0;
    0];

%[evecs,evals]=eig(A);
%w1=-9.8888, w2=-.1112, w3=-2
%
%INITIAL CONDITIONS
u=[1;1;1];

fprintf('1=Euler Explicit \n');
fprintf('2=Euler Implicit \n');
fprintf('3=Predictor Corrector \n');
method=input('Enter the method you would like \n');

h=input('Enter the value of h \n');
t=input('Enter the number of timesteps\n');

b=1;

if method==1
   for i=0:t
   %u_n+1=u_n+h(u')n
   u=u+h*(A*u+f)
   plot(u);
   pause;
   end
end
if method==2
   inversion=(eye(3,3)-h*A)^-1;
   for i=0:t
   %u_n+1=u_n+h(u')n+1
   u=inversion*(u+h*f)
   plot(u);
   pause;
   end
end

if method==3
   for i=0:t
   %u_n+1/2=u_n+h(u')n
   utemp=u+h*(A*u+f);
   %u_n+1=u_n+1/2*h((u')n+1/2+(u')n)
   u=u+.5*h*(A*utemp+A*u+2*f)
   plot(u);
   pause;
   end
end