Question: Your Task Write a function called BallBounce that takes in values for the initial height of a ball above the ground ( h 1 )

Your Task
Write a function called BallBounce that takes in values for the initial height of a ball above the ground (h1) and the coefficient of restitution between the ball and the ground (e) that does the following:
Finds the total distance traveled by the object in the limit that the number of bounces goes to infinity. This value should be the first output of your function.
Finds the number of bounces required for the ball to travel at least \(95\%\) of the total distance it will travel. This value should be the second output of your function. Note that if the coefficient of restitution is very small, the ball will travel \(95\%\) of the total distance after 0 bounces (i.e., during the initial fall to the ground).
Define a row vector that stores the distance traveled as a function of the number of bounces. The last element of this row vector should be the distance traveled once the condition described above is met. This vector should should be the third output of your function. You can perform a preliminary check of this variable by making sure its first element corresponds to the distance traveled for 0 bounces.
Function
```
function [TotalDist, BounceOut, z]= BallBounce(h1, e)
TotalDist = h1*((1+ e^2)/(1- e^2));
distance =0;
BounceOut =0;
Height = h1;
z =[h1];
while distance 0.95* TotalDist
if BounceOut >0
Height = Height * e;
distance = distance +2* Height;
z =[z, distance];
else
distance = h1;
end
BounceOut = BounceOut +1;
end
BounceOut = BounceOut +3;
if z(end)>0.95* TotalDist
z(end)=[];
end
end
```
Code to call your function ?
```
h1=1;
e =0.7
[TotalDist,BounceOut,z]= BallBounce(h1,e)
```
Output
```
TotalDist =
2.9216
BounceOut =
6
z =
1.0000
2.4000
```
Previous Assessment: 2 of 3 Tests Passed (78\%)
Check total distance calculation.
Check number of bounces calculation.
Check distance as a function of number of bounces.
Make sure your output here is a vector. Also make sure the last element of the vector is the distance traveled for the number of bounces that satisfies the minimum distance traveled condition.
Your Task Write a function called BallBounce that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!