%
%   BOMBS.M   Plot solution to the "Bombs Away" example (Differential Equations)
%
%   The solution to the "Bombs Away" example with a 2 second delay gives (see Notes):
%      yb(t) = ybo - (1/2)gt^2                 (position of the bomb)
%      yp(t) = vpo(t-2) + g(-2 + 2t -(1/2)t^2) (position of the projectile for t > 2)
%                                                
%   The projectile and bomb collide when yb(t) = yp(t), which gives
%      vpo = [ybo - g(2T-2)]/(T-2)   for T > 2 sec  (T here is time to collision)
%
%   Let's plot time to collision (T) versus initial projectile velocity (vpo)
%   Also plot collision height (H = yb(T)) versus initial velocity
%
%   File prepared by J. R. White, UMass-Lowell (last update Jan. 2003)
%

%
%   getting started
      clear all;   close all;   nfig = 0;
%
%   define some initial parameters
      ybo = 800;     % initial height of bomb (ft)
      g = 32.2;      % gravitational acceleration constant (ft/s^2)
%
%   define range of reasonable collision times (seconds)
      T = linspace(3,7,20);
%
%   now evaluate desired quantities 
%   (Note: "Dot arithmetic" is used here to evaluate the desired quantities at 20 
%   different collision times in a single statement -- this vector processing 
%   capability is one of the many very nice features available in Matlab)
      vpo = (ybo - g*(2*T-2))./(T-2);  % initial velocity for given collision times
      H = ybo -(1/2)*g*T.^2;           % collision height bs collision time
%
%   plot desired quantities
%   (Note: One usually does not plot two functions with different units on the same 
%   plot.  One way to plot two different quantities against the same variable on a 
%   single page is to use Matlab's subplot capability.  Here we plot collision time 
%   vs initial velocity in the upper plot and show the collision height vs initial 
%   velocity in the lower plot.)
      nfig = nfig+1;   figure(nfig)
      subplot(2,1,1),plot(vpo,T,'r-','LineWidth',2), grid
      title('Collision Parameters for the "Bombs Away" Example')
      ylabel('Collision Time (sec)')
%
      subplot(2,1,2),plot(vpo,H,'g:','LineWidth',2), grid
      ylabel('Collision Height (ft)'),xlabel('Initial Projectile Speed (ft/sec)')
      gtext('Delay Time = 2 sec')
%
%   end of program
