[[ PLEASE USE MATLAB]] A cannon is fired on level ground. Assign the initial vel
ID: 2088300 • Letter: #
Question
[[ PLEASE USE MATLAB]]
A cannon is fired on level ground. Assign the initial velocity (v0) to 10 m/s and an initial elevation angle of theta- 20 degrees. Using a while loop, calculate the x and y position of the cannon ball in time steps of 0.05 seconds until the cannon ball hits the ground. Assume the initial position is (x,y) = (0,0). The vertical acceleration due to gravity is -9.8 m/s2. 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 in HW2.)Explanation / Answer
clc
clear all
close all
t(1) = 0;
gravity = 9.8;
V = 10;
theta = 20*pi/12;
y0 = 0;
x0 = 0;
i = 1;
y = [];
x = [];
y(1) = 0;
while (1)
y(i) = y0 - 0.5 * gravity * t(i)^2 + V*sin(theta)*t(i);
x(i) = x0 + V*cos(theta)*t(i);
if y(i)< 0 && i>1
break
end
i = i + 1;
t(i) = t(i-1) + 0.1;
end
t = t(1:end-1);
y = y(1:end-1);
x = x(1:end-1);
figure(1)
plot(t,x)
grid on
title('x(t) vs. t')
xlabel('Time (s)')
ylabel('Horizontal Distance ( in m)')
figure(2)
plot(t,y)
grid on
title('y(t) vs. t')
xlabel('Time (s)')
ylabel('Vertical Distance(in m)')
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.