In: Physics
MatLab
Bouncing ball
When a ball is dropped from 2 m, it only has potential energy initially. When it hits the ground all that energy is converted to kinetic energy. Write a program that will calclate the position of the ball (y) as a function of time. Calculate y when the ball is always higher than 0.5 m. Note that every time the ball hits the ground it loses 10% of the total energy. Plot y vs. t. The mass of the ball is 10 kg. Other helpful information: KE = ½ mv2 PE = mgh Use the equation we have been using for the y position of the ball
i need this done in matlab
dt = 0.001;
g = 10; % Gravitational acceleration in m/s^2
h = 2; % Initial height in meter
i = 1;
for itr = 1:30
flag = 0;
t = 0;
while flag == 0 % Falling down from maximum height
y = 0.5*g*t^2;
y = h - y;
Y(i) = y;
t = t + dt;
i = i+1;
if t > sqrt(2*h/g)
flag = 1;
end
end
t = 0;
while flag == 1 % Moving upward
u = sqrt(2*g*h*0.9); % Initial velocity (after collision)
y = u*t - 0.5*g*t^2;
Y(i) = y;
t = t + dt;
i = i+1;
if t > u/g
flag = 0;
h = u^2/(2*g); % Maximum height
end
end
end
n = length(Y);
time = 0:dt:(n-1)*dt;
plot(time,Y);
xlabel('t'); ylabel('y(t)');
p = input('Enter the time in second ');
if p > max(time)
disp(['Please enter time < ',num2str(max(time))]);
else
ind = find(time == p);
disp(Y(ind));
end