clc, format compact, clear all; % Clear all temp variables
disp ('-------------------------------------------------------------')
disp (' ')
disp ('Canada Physics 250 Lab 5, computations for Ballistic Pendulum')
disp (' ')
disp ('-------------------------------------------------------------')

projectileMass = .0655; % Projectile is 0.0655 kg, 65 grams
armMass        = .245;  % Pendulum is .245 kg,  245 grams
gravityF       = 9.8;   % Force of gravity
armLength      = .285;  % Distance to pendulum center of mass
lab1High       = 4.9;   % Muzzle velocity from  lab #1, "High" setting
lab1Medium     = 3.6;   % Muzzle velocity from  lab #1, "Medium" setting
lab1Low        = 2.3;   % Muzzle velocity from  lab #1, "Low" setting


% Compute average angle 

highAngles=[37.5, 38.0, 38.3, 38.5];   % Four tests strong firing setting
thetaHigh = mean(highAngles);          % Arm swing, strong firing setting

mediumAngles=[28.3, 28.3, 28.5, 28.0]; % Four tests, medium firing setting
thetaMedium = mean(mediumAngles);      % Arm swing, medium firing setting

lowAngles = [18, 18, 18, 18.5];        % Four tests, low firing setting
thetaLow  = mean(lowAngles);           % Arm swing, low firing position


% How high did projectile rise after impact?

highElevation   = armLength - (armLength * cosd(thetaHigh));
mediumElevation = armLength - (armLength * cosd(thetaMedium));
lowElevation    = armLength - (armLength * cosd(thetaLow));


% Velocity after projectile and pendulum become a single mass

vAfterCollisionHigh   = sqrt(2 * gravityF * highElevation);
vAfterCollisionMedium = sqrt(2 * gravityF * mediumElevation);
vAfterCollisionLow    = sqrt(2 * gravityF * lowElevation);


% Muzzle velocity

vBeforeCollisionHigh   = ((armMass + projectileMass) * ...
    vAfterCollisionHigh)   / (projectileMass);

vBeforeCollisionMedium = ((armMass + projectileMass) * ...
    vAfterCollisionMedium) / (projectileMass);

vBeforeCollisionLow    = ((armMass + projectileMass) * ...
    vAfterCollisionLow)    / (projectileMass);


% Energy loss is difference of final PE and initial KE: 1/2 mv^2 - mgy

energyLossHigh   = (0.5 * projectileMass * vBeforeCollisionHigh^2)   - ...
    ((armMass + projectileMass) * gravityF * highElevation);

energyLossMedium = (0.5 * projectileMass * vBeforeCollisionMedium^2) - ...
    ((armMass + projectileMass) * gravityF * mediumElevation);

energyLossLow    = (0.5 * projectileMass * vBeforeCollisionLow^2)    - ...
    ((armMass + projectileMass) * gravityF * lowElevation);


fprintf ('        Mass of pendulum, in kg................... %1.3f\n', ...
    armMass)
fprintf ('        Mass of projectile........................ %1.4f\n', ...
    projectileMass)
fprintf ('        Length of pendulum arm, in meters......... %1.3f\n', ...
    armLength)
disp    (' ')
disp    ('     1. "High" launch setting')
fprintf ('        Average arm swing, in degrees.............%2.1f\n', ...
    thetaHigh)
fprintf ('        Change in elevation, in meters............ %1.3f\n', ...
    highElevation)
fprintf ('        Muzzle velocity, in meters per second..... %1.2f\n', ...
    vBeforeCollisionHigh)
fprintf ('        Muzzle velocity from Lab #2............... %1.1f\n', ...
    lab1High)
fprintf ('        Velocity of the two combined masses....... %1.2f\n', ...
    vAfterCollisionHigh)
fprintf ('        Energy loss, in joules.................... %1.3f\n', ...
    energyLossHigh)
disp    (' ')
disp    ('     2. "Medium" launch setting')
fprintf ('        Average arm swing, in degrees.............%2.1f\n', ...
    thetaMedium)
fprintf ('        Change in elevation, in meters............ %1.3f\n', ...
    mediumElevation)
fprintf ('        Muzzle velocity, in meters per second..... %1.2f\n', ...
    vBeforeCollisionMedium)
fprintf ('        Muzzle velocity from Lab #2............... %1.1f\n', ...
    lab1Medium)
fprintf ('        Velocity of the two combined masses....... %1.3f\n', ...
    vAfterCollisionMedium)
fprintf ('        Energy loss, in joules.................... %1.3f\n', ...
    energyLossMedium)
disp    (' ')
disp    ('     3. "Low" launch setting')
fprintf ('        Average arm swing, in degrees.............%2.1f\n', ...
    thetaLow)
fprintf ('        Change in elevation, in meters............ %1.3f\n', ...
    lowElevation)
fprintf ('        Muzzle velocity, in meters per second..... %1.2f\n', ...
    vBeforeCollisionLow)
fprintf ('        Muzzle velocity from Lab #2............... %1.1f\n', ...
    lab1Low)
fprintf ('        Velocity of the two combined masses....... %1.3f\n', ...
    vAfterCollisionLow)
fprintf ('        Energy loss, in joules,................... %1.3f\n', ....
    energyLossLow)
disp    ('-------------------------------------------------------------')
disp    (' ')
disp    (' ')
disp    ('-------------------------------------------------------------')
disp    (' ')
disp    ('Canada Physics 250 Lab 5, computations for Ballistic Pendulum')
disp    (' ')
disp    ('-------------------------------------------------------------')
disp    ('     Ratios:')
disp    (' ')
disp    ('         1. Change in Elevation over Loss of Energy')
fprintf ('                 "High" launch setting....... %1.3f\n', ...
    highElevation/energyLossHigh)
fprintf ('                 "Medium" launch setting..... %1.3f\n', ...
    mediumElevation/energyLossMedium)
fprintf ('                 "Low" launch setting........ %1.3f\n', ...
    lowElevation/energyLossLow)
disp    (' ')
disp    ('         2. Energy Loss over Muzzle Velocity')
fprintf ('                 "High" launch setting......  %1.3f\n', ...
    energyLossHigh/vBeforeCollisionHigh)
fprintf ('                 "Medium" launch setting..... %1.3f\n', ...
    energyLossMedium/vBeforeCollisionMedium)
fprintf ('                 "Low" launch setting........ %1.3f\n', ...
    energyLossLow/vBeforeCollisionLow)
disp    (' ')
disp    ('         3. Muzzle Velocity over Angle of Elevation')
fprintf ('                 "High" launch setting....... %1.3f\n', ...
    vBeforeCollisionHigh/thetaHigh)
fprintf ('                 "Medium" launch setting..... %1.3f\n', ...
    vBeforeCollisionMedium/thetaMedium)
fprintf ('                 "Low" launch setting........ %1.3f\n', ...
    vBeforeCollisionLow/thetaLow)
disp    (' ')
disp    ('         4. Muzzle velocity from Lab 2 over Lab 5')
fprintf ('                 "High" launch setting....... %1.2f\n', ...
    lab1High/vBeforeCollisionHigh)
fprintf ('                 "Medium" launch setting..... %1.2f\n', ...
    lab1Medium/vBeforeCollisionMedium)
fprintf ('                 "Low" launch setting........ %1.2f\n', ...
    lab1Low/vBeforeCollisionLow)
disp    (' ')
disp    ('         5. Post- over Pre-collision Velocity')
fprintf ('                 "High" launch setting....... %1.3f\n', ...
    vAfterCollisionHigh/vBeforeCollisionHigh)
fprintf ('                 "Medium" launch setting..... %1.3f\n', ...
    vAfterCollisionMedium/vBeforeCollisionMedium)
fprintf ('                 "Low" launch setting........ %1.3f\n', ...
    vAfterCollisionLow/vBeforeCollisionLow)
disp    ('-------------------------------------------------------------')

