Revisit the cannon problem from Homework 1. A cannon is fired on level ground. A
ID: 3694842 • Letter: R
Question
Revisit the cannon problem from Homework 1. A cannon is fired on level ground. Assume the user inputs an initial velocity (vO) of 100 m/s and an initial elevation angle of theta = 25 degrees. Using a while loop, calculate the x and y position of the cannon ball in time steps of 0.1 seconds until the cannon ball hits the ground. Display the time, x-position and y-position in a nice table format with three columns. (Your output should look similar to the table from the previous cannon problem.) Remember that trigonometric functions require input in radians, not degrees. Assume the initial position is (x, y) = (0,0). The vertical acceleration due to gravity is -9.8 m/s2. Can you think of how to do this problem with a for loop? (not required)Explanation / Answer
v = 100;
ang = 25*pi/180;
vx = 100*sin(ang);
vy = 100*cos(ang);
t = 0;
disp("Time X-value Y-value");
while true
t += 0.1;
dx = vx*t;
dy = vy*t - 9.8*t*t;
if(dy<0)
break;
end
ab = [num2str(t)," ",num2str(dx)," ",num2str(dy)];
disp(ab);
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.