ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Rock physics math-thing [PHP]

(1/3) > >>

RedPillow:
Yes, this is part of a homework which I've tried to do 2 days now...
I tried to translate it as good as I can


"if rock is thrown directly up from the ground with starting speed of 20 meters/second, rock's height s (meters) after t (seconds) can be count with this formula:
s = -5t2 + 20t

Make a program, which counts and prints rock's height on each second."

I've tried this with different changes but none of them have worked so far:


--- Code: PHP ---$time = 1;$height = 1; while ($height > 0) {$height = ((-5*$time*2)+(20*$time));$time++;echo "Rock's height is " . $height . " when " . $aika . " -seconds has passed.<br />";}
And this prints out infinite lines of this:

Rock's height is 10 when -seconds has passed.
Rock's height is 20 when -seconds has passed.
Rock's height is 30 when -seconds has passed.
Rock's height is 40 when -seconds has passed.
Rock's height is 50 when -seconds has passed.
Rock's height is 60 when -seconds has passed.
Rock's height is 70 when -seconds has passed.
Rock's height is 80 when -seconds has passed.
Rock's height is 90 when -seconds has passed.
Rock's height is 100 when -seconds has passed.

It goes on and on.


So ... what am I doing wrong / not getting?

-RedPillow

mouser:
it's not your code, it's your starting formula:

s = -5t2 + 20t
--- End quote ---

this is not correct.  at least not in our universe.

if s = -5t2 + 20t this is same as saying s = 10t, which is actually what your program shows, and is clearly not a formula of much value :)

it's probably supposed to be t^2 not t*2.

RedPillow:
But the exercise told me that formula  :huh:
My teacher has messed these up before though ... any idea how to actually do this thing then?

Edit: Oh ... I'll try the t^2 one.

Am I right when I think, that the printout should be something like this:


Rock's height is 10 when 1-seconds has passed.
Rock's height is 20 when 2-seconds has passed.
Rock's height is 30 when 3-seconds has passed.
Rock's height is 40 when 4-seconds has passed.
Rock's height is 30 when 5-seconds has passed.
Rock's height is 20 when 6-seconds has passed.
Rock's height is 10 when 7-seconds has passed.
Rock's height is 0 when 8-seconds has passed.

Stoic Joker:
I could be missing something... But I see nothing that would cause the rocks travel to apex and return. So line 4's while loop is (er...) infinite...because its always counting up away from its 0 cut off point.

Eóin:
It's the -t^2 bit that causes the rock to eventually fall back to earth. Looking at height as a function of t, i.e h(t) then the derivative h'(t) is

-10*t +20

At it's max/min h'(t) = 0 => -10*t + 20 = 0 => t = 2

So the rock should reach it's peak height at t = 2 seconds.

I'm pretty positive mouser is right in assuming it should be t^2, the typo looks to me like a classic copy and paste error. Something that is extremely careless given it's coming from a teacher.

Navigation

[0] Message Index

[#] Next page

Go to full version