%cannondriver.m
% -A. Ruina  Feb 10, 2000, Lecture example
%Unlike the v4.2 lecture, this is matlab 5.x
%CANNON BALL TRAJECTORY WITH QUADRATIC DRAG

global c m g           %to pass variables
c=0; m=1; g=10;  %Set constants in consistant units (mks)

theta = 30*pi/180;   %launch angle in radians
speed0= 100;         %launch speed in m/s

v0 = speed0*[cos(theta)  sin(theta)];

z0=[ 0 0 v0]'; % order is x0, y0, vx0, vy0

tspan=[0 10];  % time interval for solution

[t z] = ode23('cannonrhs',tspan, z0);

plot (z(:,1), z(:,2))   %plot trajectory
axis('equal')           %This keeps the scale the same for x and y

title('Andy''s cannon trajectory 2/10/2000')
xlabel('x position');  ylabel('y position')


z(end,:)  % look at the x, y, vx, and vy at the end of flight
