%Stability
%Integration by 2nd order Runge-Kutta Method

clear all


hlambdaR=[-4:0.01:2];
hlambdaI=[-3:0.01:3];

for k=1:601
   for j=1:601
      hlambda=hlambdaR(k)+i*hlambdaI(j);
      Z(j,k)=(1+hlambda+(hlambda^2)/2);
      %Z(j,k)=(1+hlambdaR(k)+(hlambdaR(k)^2-hlambdaI(j)^2)/2)^2+(hlambdaI(j)+hlambdaR(k)*hlambdaI(j))^2;
   end
end


figure(1)
contourf(hlambdaR,hlambdaI,-abs(Z),[-1 -1])
title('STABILITY - 2nd ORDER RUNGE-KUTTA')
xlabel('\lambda_{R}h')
ylabel('\lambda_{I}h')
hold on
plot([0 0],[-3 3],'k-')
plot([-4 2],[0 0],'k-')
hold off

figure(2)
contour(hlambdaR,hlambdaI,-abs(Z),[-1 -1])
title('STABILITY - 2nd ORDER RUNGE-KUTTA')
xlabel('\lambda_{R}h')
ylabel('\lambda_{I}h')
hold on
plot([0 0],[-3 3],'k-')
plot([-4 2],[0 0],'k-')
hold off