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𝑔𝑡²
and gravitational acceleration 𝑔 is here taken as negative.
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.
Hint ; Motion under gravity is described by the equation :Sy = V0y t + (1/2)gt^2
and gravitational acceleration g is here taken as negative.
%}
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);
Comments
Leave a comment