Answer to Question #311932 in MatLAB for Dee

Question #311932

A ball is thrown vertically upwards with an initial velocity of 30 m/s.





Using a time step of 0.02 s up to 6.20 s, write a matlab code to give a plot of the vertical distance versus





time for this ball.





Hint ; Motion under gravity is described by the equation : 𝑣𝑦 = 𝑣𝑜𝑦𝑡 +1/2𝑔𝑡^2





and gravitational acceleration 𝑔 is here taken as negative.





Then use your code to answer the following questions:





(i) To what maximum height does the ball rise?





(ii) What is the index of time at maximum height?





(iii) How long does it take the ball to ascend to maximum height?





(iv) How long does it take the ball to hit the ground?





(v) What happens to the ball if the sign for gravitational acceleration is taken as positive?

1
Expert's answer
2022-03-19T02:24:15-0400
close all,
clear all,
clc,




%{
    A ball is thrown vertically upwards with an initial velocity of 30 m/s.
    Using a time step of 0.02 s up to 6.20 s, write a matlab code to give a plot of the vertical distance versus
    time for this ball.
%}  


u = 30; %Initial Velocity m/s
V0 =30; %m/s, Initial Velocity
t = 0:0.02:6.20;    %Time Step
g = 9.8;    %Gravity g in m/sec^2


%{
S = [];
for r=1:length(t)
    S(r) = V0 - ((1/2)*g*t(r)*t(r));
end
scrsz = get(0,'ScreenSize');
Dim=0;
figure('Position',[scrsz(1)+Dim, scrsz(2)+Dim,scrsz(3)-20,scrsz(4)-100]);
plot(t,S,'r');
grid on,
xlabel('--- Time(t) --->');
ylabel('--- Vertical Distance (meters) --->');
title('Plot: Vertical Distance vs time','FontSize',20);
%}


%(i) To what maximum height does the ball rise? v^2 = u^2 - 2gh
%At maximum height, v = 0, therefore,   h = (u^2/2g)
MaxHeight = (u*u)/(2*g);
fprintf('\n\tMaximum Height = ',MaxHeight);




%(ii) What is the index of time at maximum height?
%h = ut - (1/2)gt^2
A = -(1/2)*g;
B = u;
C = -MaxHeight;
t1 = ((-B)+((B^2-4*A*C))^0.5)/(2*A);
t2 = ((-B)-((B^2-4*A*C))^0.5)/(2*A);
fprintf('\n\tMaximum time to reach the maximum height = %f seconds',t1);
fprintf('\n\tMaximum time to reach the maximum height = %f seconds',t2);


%(iii) How long does it take the ball to ascend to maximum height?
%h = ut - (1/2)gt^2
A = -(1/2)*g;
B = u;
C = -MaxHeight;
t1 = ((-B)+((B^2-4*A*C))^0.5)/(2*A);
t2 = ((-B)-((B^2-4*A*C))^0.5)/(2*A);
fprintf('\n\tHow long does it take the ball to ascend to maximum height? = %f seconds',t1);




%(iv) How long does it take the ball to hit the ground?
fprintf('\n\tMax. time to hit the ground = %f',2*t1);


%(v) What happens to the ball if the sign for gravitational acceleration is taken as positive?
fprintf('\n\nIf g is taken as +ve, that means ball is thrown from top to ground.');


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS