% cannon_plot.m
%  A cannonball is fired at an angle ALPHA, with initial velocity V0.
%  Plot its location at successive seconds.
%
tmax = input ( 'Enter the final second to consider: ' );
degrees = input ( 'Enter the angle, in degrees: ' );
angle = degrees * pi / 180.0;
x0 = input ( 'Enter x position of cannon: ' );
y0 = input ( 'Enter y position of cannon: ' );
v0 = input ( 'Enter initial velocity, in feet/second: ' );

xlist = [];
ylist = [];

for t = 0 : tmax

  x = x0 + v0 * cos ( angle ) * t; 
  y = y0 + v0 * sin ( angle ) * t - 16.0 * t^2;

  fprintf ( '%d seconds,  (%g, %g) feet\n', t, x, y );
  xlist = [ xlist, x ];
  ylist = [ ylist, y ];

end

plot ( xlist, ylist );
title ( 'Cannonball trajectory' );

