%% YOURNAME (DUEDATE)
%
% *IMPORTANT:*
%
% Do not change *anything* in this header (besides your
% name and due date above as needed)!
%
% Put your solution to the exercise completely at the end
% of this file.
%
%%
% <latex>
% % for Octave, or for Matlab published to LaTeX for proclatex
% \input{../setup.tex}
% </latex>
%
%% ORDINARY DIFFERENTIAL EQUATIONS, Exercise 2

if ~exist('___code___','var') ; clear ; end
format compact
more off


%% EXERCISE DESCRIPTION:
%
% Use the created function |CannonBall| with |ode45| to
% solve the motion of a cannon ball in air.  This script
% already contains the analytic solution without air
% resistance to compare with.


%% Check the Instructor
%
% Never trust the instructor!  Check what the instructor
% claims is the exact solution without air resistance.
%
% According to elementary physics, without air resistance
% the horizontal and vertical positions |x| and |y| of
% the cannon ball are given by
%
%             x = V0 cos(alpha) t
%             y = V0 sin(alpha) t - 0.5 g t^2
%
% where |V0| is the initial speed of the cannon ball and
% |alpha| the angle at which it comes out of the cannon.
% Setting |y| equal to zero gives the final time at which
% the cannon ball is back on the ground, call it
% |tFinal|.  Substituting that time into the equation for
% |x| then gives the final value of |x|, call it
% |xFinal|, which is how far the cannon ball has
% traveled.  You get
%
%           tFinal = 2 V0 sin(alpha) / g
%           xFinal = 2 V0^2 sin(alpha) cos(alpha) / g
%                  = V0^2 sin(2 alpha) / g
%
% Note that the distance |xFinal| travelled is maximal if
% |alpha| is 45 degrees.  It is then |V0|^2/g.

% the acceleration of gravity
g=9.81

% the initial velocity
V0=100

% the angle that we shoot the ball out, in degrees
alpha=45

% the time back on the ground without air resistance
tFinal=2*V0*sind(alpha)/g
disp('The instructor claims the above is 14.42 s.')

% the final x, being the horizontal distance travelled
xFinal=2*V0^2*sind(alpha)*cosd(alpha)/g
disp('The instructor claims the above is 1019 m.')


%% Additional file: CannonBall.m
% <include>CannonBall.m</include>


%% SOLUTION:


