MATLAB Answers

I need help coding a human cannonball ignoring air resistance

5 views (last 30 days)
Tiffany Orogun
Tiffany Orogun on 11 Mar 2020
Commented: Jim Riggs on 13 Mar 2020
I need to make a code on matlab for a human cannon ball, without taking drag into account. It's meant to be a simple code but i've only seen complicated solutions for the cannonball. I need it to be at an angle of 45. The cannonball angle has to be a vector. If possible without needing a while loop.

  1 Comment

darova
darova on 11 Mar 2020
Do you have any attempts? What problems are yuo facing?

Sign in to comment.

Answers (1)

Jim Riggs
Jim Riggs on 12 Mar 2020
Edited: Jim Riggs on 12 Mar 2020
Assuming zero drag and relatively low muzzle velocity ( acceleration due to gravity = constant), the point-mass trajectory can be described by simple kinematic relationships.
(See derivations in the attached paper)

  2 Comments

Tiffany Orogun
Tiffany Orogun on 13 Mar 2020
Thank you so much. I've coded this much, but i'm now having problems plotting two graphs to show variance in the trajectories. I tried but my second graph doesn't stop when it hits the x-axis (when y = 0).
release_vel= 40:0.5:70; % We have assumed a range of velocities from 40m/s to 70m/s at intervals of 0.5m/s
mass = 75; % Average mass of a person in the UK is around 75kg
cannon_angle = 30:5:60; % We have assumed a range of angles for the cannon from 30deg. to 60deg. at intervals of 5deg.
cannon_angle2 = 40:5:70
vertical_vel = release_vel'.*sind(cannon_angle); %In order to calculate the time it takes the human to reach the top we need to calculate the vertical component of his velocity in order to use SUVAT equations
vertical_vel2 = release_vel'.*sind(cannon_angle2);
time_to_top = (0 - vertical_vel)/-9.81; % To calculate the time it takes for the person to reach the maximum height we have used the equation v = u + at, substituting our values for u and using gravity as a. We have ignored the effects of air resistance as they are negligible in this case
time_to_top2 = (0 - vertical_vel2)/-9.81;
time_from_top_to_net = (vertical_vel - 0)/9.81; % Assuming that the landing net is at the same height as the point of release from the cannon, the time taken for the person to fall from the maximum height to the net will be the same as the time the person takes to reach the top from the cannon release point
time_from_top_to_net2 = (vertical_vel2 - 0)/9.81;
total_time_taken = time_to_top + time_from_top_to_net % The total time taken for release to landing will be the sum of the time taken for the person to reach the top of the trajectory (i.e. time_to_top) and the time that it takes the person to fall back down to the net (i.e.time_from_top_to_net)
total_time_taken2 = time_to_top2 + time_from_top_to_net2 % The total time taken for release to landing will be the sum of the time taken for the person to reach the top of the trajectory (i.e. time_to_top) and the time that it takes the person to fall back down to the net (i.e.time_from_top_to_net)
horizontal_vel = release_vel'*cosd(cannon_angle); %In order to calculate the horizontal displacement of the human, first we have resolved his release velocity into its horizontal component
horizontal_vel2 = release_vel'*cosd(cannon_angle2);
horizontal_displacement = horizontal_vel.*total_time_taken %We have used the equation s = vt, using the horizontal component of the release velocity, to calculate the horizontal displacement of the human
horizontal_displacement2 = horizontal_vel2.*total_time_taken2
v = 50; %In order to plot the graph of the human's motion we took an average value for his release velocity so that our graph was clearer and only showed one path
v2 = 60
angle = 45; %This is the average value of the cannon angle that we have chosen to plot our graph
angle2 = 60
t = (2*v*sind(angle))/9.81; %We have used the equation t = (2*initial_velocity*angle)/g in order to calculate the time that it will take for this specific trajectory using our chosen values for the velocity and angle
t2 = (2*v*sind(angle2))/9.81;
tvalues = 0:(t/100):t; %These are the values of time that we have chosen along the path that the human will follow. In the following lines we will be calculation the displacement of the human at each of these moments in time so that we can plot a graph joining all of these points to show the trajectory of the projectile
tvalues2 = 0:(t2/100):t2;
shoriz = v*cosd(angle).*tvalues; %This equaation is used to calculate the horizontal displacement of the human at each moment in time chossen in line 16
shoriz2 = v2*cosd(angle).*tvalues2;
svertic = v*sind(angle).*tvalues + (1/2)*-9.81*tvalues.^2; %This equation is used to calculate the vertical displacement of the human at each moment in time chosen in line 16
svertic2 = v2*sind(angle).*tvalues2 + (1/2)*-9.81*tvalues2.^2;
plot(shoriz,svertic, 'r',) %This plots the horizontal displacement of the human against the vertical displacement of the human, giving us a plot of his motion
hold on
plot(shoriz2,svertic2, 'm')
Jim Riggs
Jim Riggs on 13 Mar 2020
The reason that tghe second plot does not stop in the correct place is because you have defined the time span incorrectly for the second case.
You used the same horizontal velocity (v) for both. The second case (for t2) should use v2.
t = (2*v*sind(angle))/9.81; %We have used the equation t = (2*initial_velocity*angle)/g
% in order to calculate the time that it will take for this specific trajectory
% using our chosen values for the velocity and angle
t2 = (2*v*sind(angle2))/9.81;
(Also, you should get in the habit of NEVER hard-coding numeric constants in equations.
Use g=-9.81 or grav = -9.81 Ths will make your code more versitile in the future when you want to run the same calculation, but account for variations in g due to lattitude, (or on Mars, maybe) )

Sign in to comment.


Translated by