Program this equation using matlab for loops A ball is dropp
Program this equation using matlab for loops:
A ball is dropped from a building with height, H meters. The ball is started at rest and release at t=0s.
a) Use matlab’s for loops, plot:
Displacement vs. velocity graph
displacement vs. time graph
Velocity vs. time graph
b) If the ball hit the ground when it reach its velocity = 30 m/s, and it bounce back once
Plot its velocity vs. time graph and displacement vs time graph
Solution
a)
H=input(\'Enter the value for H\' ); %takin input for H
g=-9.8
s=[H:-1,0]; % Specifying limits of graph
v=sqrt(2*g*s); %relationship for calculating velocity
plot(s,v)
s=[H:0] % taking points for displacement
for s =[1:H] % taking input for every H
t[s]=sqrt(2*s/g)
end
for i=1:length(t)
plot(s(i),t(i)) %plotting using for loop . It will print the points
end
syms time
eqn1= H-0.5*g*time^2==0; % solving for time to reach ground
Tfin=solve(eqn1,time);
t=[0:Tfin]
v=g.*t
for i=1:length(t)
plot(v(i),t(i)) %plotting using for loop
end
b)
u=30;
g=-10;
t=[1:100];
v=u+g*t;
plot(v,t); %for these i am not using for loop. plot(x,y) will generate the graph
t=[1:100];
s=u*t+0.5*g*t^2;
plot(s,t);

