Jump to content

[SOLVED] Coefficient of a Restitution Hints


kaveman50

Recommended Posts

Hello. I was wondering if anyone can give me hints on how to write this program...

 

The coefficient of a restitution of a ball, a number between 0 and 1, specifiies how much energy is conserved when a ball hits a rigid surface.  A coefficient of .9, for instance, means a bouncing ball will rise 90 percent of its previous height after each bounce.  Write a program to input a coefficient of restitution and an intial hright in meters, and report how many times a ball bounces when dropped from its initial height before it rises to a height of less than 10 centimeters.  Also report the total distance traveled by the ball before this point.  The coefficients of restitution of a tennis ball, basketball, super ball, and softball are 0.7, 0.75, 0.9, and 0.3, respectively.

Link to comment
Share on other sites

To calculate the number of bounces would be very simple.

 

ex:

 

$height = 100; //initial hight in centimeters
$restitution = .7;
$bounces = 0;
while($height > 10)
{
     $height = pow($height, $restitution);
     $bounces++;
}
echo $bounces;

 

As for the distance traveled you'd need to factor another force into the system.

Link to comment
Share on other sites

Perhaps I'm misunderstanding the problem, but isn't "$height = pow($height, $restitution);" incorrect?

 

After all, if you're initial height is 100 centimeters, and based on the coefficient in his problem (new height = old height * coefficient), your line will give a result of 25.119 centimeters after 1 bounce. But by the definition of his problem (new height = 100 * 0.7) the new height should be 70 centimeters.

 

"$height = pow($height, $restitution);"

 

should be

 

"$height = $height * $restitution;"

 

?

Link to comment
Share on other sites

Perhaps I'm misunderstanding the problem, but isn't "$height = pow($height, $restitution);" incorrect?

 

After all, if you're initial height is 100 centimeters, and based on the coefficient in his problem (new height = old height * coefficient), your line will give a result of 25.119 centimeters after 1 bounce. But by the definition of his problem (new height = 100 * 0.7) the new height should be 70 centimeters.

 

"$height = pow($height, $restitution);"

 

should be

 

"$height = $height * $restitution;"

 

?

 

Ahh, yes. I misread the problem.

Link to comment
Share on other sites

When I enter the code below, all it does is display the text boxes and a 7 below. When I enter numbers to test it, nothing happens. Perhaps something is wrong with my html?

 

<form method='post' action=''>

Coefficient of Restitution: <input type="text" name="height" id='num1' />

<br/>

<br/>

Initial Height in Meters: <input type="text" name="restitution" id='num2' />

<input type='Submit' name='Submit' value="Submit" />

</form>

 

 

 

 

<?

$height=$_POST['num1'];

$restitution=$_POST['num2'];

 

$height = 100;

$restitution = .7;

$bounces = 0;

while($height > 10)

{

$height = $height * $restitution;

    $bounces++;

}

echo $bounces;

?>

Link to comment
Share on other sites

And to capture the total distance travelled (assuming your talking vertical movement only. You should only have to put something like...

 

$distance += $height;

 

... as the first line of the while loop. It may require some tweaking to make sure your including the first and last bounce, but you should be able to work that out.

Link to comment
Share on other sites

And to capture the total distance travelled (assuming your talking vertical movement only. You should only have to put something like...

 

$distance += $height;

 

... as the first line of the while loop. It may require some tweaking to make sure your including the first and last bounce, but you should be able to work that out.

 

Actually, this will cause it only to measure the "down" vertical distance.

 

If you need to get the total vertical distance traveled:

 

<?
$height=(int)$_POST['height'];
$restitution=(int)$_POST['restitution'];

$distance = height;
$bounces = 0;
while($height > 10)
{
$height = $height * $restitution;
$distance += $height*2;
     $bounces++;
}
echo 'bounces: '.$bounces.'<br/>';
echo 'distance: '.$distance;
?>

 

The fix for the 0 problem is above.

Link to comment
Share on other sites

D'oh, yes, I forgot the reverse of the bounce. That code won't be right either though unless I'm mistaken. The height variable is missing a dollar on line 5 (just a typo I know). Your casting $restitution as an int when its a decimal number.

Link to comment
Share on other sites

Nice catches cags!

 

<?
$height=(int)$_POST['height'];
$restitution=(float)$_POST['restitution'];

$distance = $height;
$bounces = 0;
while($height > 10)
{
$height = $height * $restitution;
$distance += $height*2;
     $bounces++;
}
echo 'bounces: '.$bounces.'<br/>';
echo 'distance: '.$distance;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.