Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 06, 2016, 01:52:00 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Rock physics math-thing [PHP]  (Read 2421 times)

RedPillow

  • Member
  • Joined in 2008
  • **
  • Posts: 141
  • Pillows.
    • View Profile
    • Read more about this member.
    • Donate to Member
Rock physics math-thing [PHP]
« on: January 19, 2011, 05:52:28 AM »
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 [Select]
  1. $time = 1;
  2. $height = 1;
  3.  
  4. while ($height > 0) {
  5. $height = ((-5*$time*2)+(20*$time));
  6. $time++;
  7. echo "Rock's height is " . $height . " when " . $aika . " -seconds has passed.<br />";
  8. }

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

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,406
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #1 on: January 19, 2011, 05:57:54 AM »
it's not your code, it's your starting formula:

Quote
s = -5t2 + 20t

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.
« Last Edit: January 19, 2011, 06:02:23 AM by mouser »

RedPillow

  • Member
  • Joined in 2008
  • **
  • Posts: 141
  • Pillows.
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #2 on: January 19, 2011, 06:03:18 AM »
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.

« Last Edit: January 19, 2011, 06:08:12 AM by RedPillow »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,296
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #3 on: January 19, 2011, 06:17:32 PM »
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

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #4 on: January 19, 2011, 07:41:09 PM »
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.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,296
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #5 on: January 20, 2011, 06:49:36 AM »
Okay, thanks

It's been (quit) a while since I've done anything with formulas, and can't for the life of me recall what ^ does/means/is telling it to do.

worstje

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 571
  • The Gent with the White Hat
    • View Profile
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #6 on: January 20, 2011, 07:17:15 AM »
To put it really simply, ^ (english: to the power of) says how often something needs to be multiplied with itself.

x^1 = x
x^2 = x * x
x^3 = x * x * x
x^4 = x * x * x * x
x^5 = x * x * x * x * x
x^6 = x * x * x * x * x * x
etc

Of course, with negatives (x^(-2)) and non-whole numbers (x^pi) it isn't as simple or intuitive to demonstrate, but the same principles apply mathematically. However, negative powers can be rewritten like this:

x^-y  = 1 / (x^y)

At least, I hope my math isn't failing me as I haven't used this stuff in a while. :)
« Last Edit: January 20, 2011, 07:19:52 AM by worstje »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,296
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #7 on: January 20, 2011, 07:28:34 AM »
Oh yeah, that...

Crap  :-[ I shoulda remembered  that one.

Thank you,

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #8 on: January 20, 2011, 10:03:25 AM »
Also the forum bbcode supports sup and sub, so things can be made look more mathsey

s = -5t2 + 20t   :Thmbsup:

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,367
    • View Profile
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #9 on: January 20, 2011, 10:47:36 AM »
Unusual though it may be to find a post from me that is anything other than facetious, fallacious, or frumentarious, mathematical formulae are something of a speciality of mine. I think some of you gentlemen would benefit from an example in order to keep your wits sharp. So, here is a challenging little example…

Find x
Sickim.jpg




worstje

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 571
  • The Gent with the White Hat
    • View Profile
    • Donate to Member
Re: Rock physics math-thing [PHP]
« Reply #10 on: January 20, 2011, 12:37:16 PM »
That one is so simple and so standard I actually redid the math twice to make sure I wasn't getting it wrong (you implied something like challenging and that it is about sharp wits, and I'm afraid it ranks nowhere close to that for me. 8))