function eqlbrm(inter,ic,n,A)
h=(inter(2)-inter(1))/n;                  % plot n points in total
y(1,:)=ic;                % enter initial conds in y
t(1)=inter(1);
flg = 0;
set(gca,'xlim',[-2.7 2.7],'ylim',[-2.7 2.7], ...
  'XTick',[-2.5 0 2.5],'YTick',[-2.5 0 2.5], ...
  'Drawmode','fast','Visible','on','NextPlot','add');
cla;         
axis square               % make aspect ratio 1 - 1
bob = line('color','r','Marker','.','markersize',40,...
    'erase','xor','xdata',[],'ydata',[]);
rod = line('color','b','LineStyle','-','LineWidth',3,...
    'erase','xor','xdata',[],'ydata',[]);
%%v = VideoWriter('eqlbrm','MPEG-4');open(v)
for k=1:n/10
  %%frame = getframe;writeVideo(v,frame);
  t(k+1)=t(k)+h;
  y(k+1,:)=trapstep(t(k),y(k,:),h,A);
  xbob = 2.5*sin(y(k+1,1)); ybob = -2.5*cos(y(k+1,1));
  %xbob
  if ybob > 2.4
      disp(A)
      disp('is unstable')
      flg = 1;
      break
  end
  xrod = [0 xbob]; yrod = [0 ybob];
  set(rod,'xdata',xrod,'ydata',yrod)
  set(bob,'xdata',xbob,'ydata',ybob)
  xlabel(['A = ' num2str(A)])
  drawnow; pause(h)
end
if flg == 1
    A = A - 0.05;
    eqlbrm([0 1000], [0.01 0], 10000, A)
else
    disp(A)
    disp('is stable')
    A = A + 0.005;
    eqlbrm([0 1000], [0.01 0], 10000, A)
end
%%close(v)

function y = trapstep(t,x,h,A)
%one step of the Trapezoid Method
z1=ydot(t,x,A);
g=x+h*z1;
z2=ydot(t+h,g,A);
y=x+h*(z1+z2)/2;

function z=ydot(t,y,A)
g=9.81;length=2.5;
z(1) = y(2);
%part 4&5
%z(2) = -(g/length)*sin(y(1)) - 1*y(2) + 12*sin(t);
%part 6&7
z(2) = -((g/length)+ A*cos(2*pi*t))*sin(y(1)) - 0.1*y(2) ;