clc
disp('Press any key to display simulation results.')
pause

%....Plotting commands..................................................
f1=figure; 
set(f1,'Units','normalized','Position',[0.05 0.05 0.65 0.65])
clf 

%create the axes
h_graphic=axes('position',[0.1 0.1 0.8 0.8]);
axis equal
ymax=max(y);
axis([-0.1*a 1.1*a -1.1*ymax 0.1*b])
xlabel('m'), ylabel('m')
title('Particle''s trajectory')

%initialize the graphic object handles
x0=0;
y0=0;
l_traj=line('xdata',x(:),'ydata',-y(:),'marker','none','erasemode','none',...
    'LineStyle','-','color','b');

theta=atan(b/a);
x2=g/4*sin(2*theta)*t.^2;
y2=g/2*sin(theta)^2*t.^2;
l_traj2=line('xdata',x2(:),'ydata',-y2(:),'marker','none','erasemode','none',...
    'LineStyle','--','color','b');

h_part=line(x0,y0,'color','k','marker','.','markersize',20,...
    'erasemode','background');

h_part2=line(x0,y0,'color','r','marker','.','markersize',20,...
    'erasemode','background');

h_text=text(0,-0.8*ymax,'t=0','erasemode','background');

disp('Press any key for animation')
pause

%create animation
for i=1:length(t)
    set(h_part,'xdata',x(i),'ydata',-y(i));
    set(h_part2,'xdata',x2(i),'ydata',-y2(i));
    set(h_text,'string',strcat('t=',num2str(t(i))));
    drawnow
end

l_traj=line('xdata',x(:),'ydata',-y(:),'marker','none','erasemode','none',...
    'LineStyle','-','color','b');
l_traj2=line('xdata',x2(:),'ydata',-y2(:),'marker','none','erasemode','none',...
    'LineStyle','--','color','b');

%disp('Press any key to close the figure window.')
%pause
%close(f1)