Simple PHP Troubleshoot

Discussion in 'OT Technology' started by makavelimx, Aug 3, 2005.

  1. makavelimx

    makavelimx Guest

    <?php

    $a = 100*
    3.1415926535897932384626433832795028841971693993751058159;

    $b = $i*$i*3.1415926535897932384626433832795028841971693993751058159;

    while ($b-$a=$a/2) {

    $i=$i+0.001; }

    echo $i

    ?>

    I'm trying to get this to work and echo a number for $i.

    Basically $a and $b are circles.

    $a-$b=$a/2 by having this true, I want to find $i, which is the length of the radius of circle $b.

     
    Last edited by a moderator: Aug 3, 2005
  2. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    since $i hasnt been set, it has a value of 0 on line 2
    your while statement needs to be a == not =
    your while statement will never break either once they are equal, ull get an infinite loop
    and use pi() instead of specifying pi
     
    Last edited: Aug 3, 2005
  3. zeke676

    zeke676 New Member

    Joined:
    Jul 11, 2005
    Messages:
    212
    Likes Received:
    0

    or just use declare a constant with 3.14159 you dont need the whole number
     
  4. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    PHP:
    <?php
    /* setting initial variable values */
    $i 0;
    $a 100 3.1415926535897932384626433832795028841971693993751058159;
    $b $i $i 3.1415926535897932384626433832795028841971693993751058159;
     
    /* running the loop till value is found */
    while (($b $a) == ($a 2)) {
        
    $i $i 0.001;
        
    $b $i $i 3.1415926535897932384626433832795028841971693993751058159;
    }
     
    /* printing the found value */
    echo $i;
     
    ?>
    OR
    PHP:
    <?php
    /* setting initial variable values */
    $a 100 3.1415926535897932384626433832795028841971693993751058159;
     
    /* running the loop till value is found */
    for ($i 0; ($b $a) == ($a 2); $i $i 0.001) {
        
    $b $i $i 3.1415926535897932384626433832795028841971693993751058159;
    }
     
    /* printing the found value */
    echo $i;
     
    ?>
    That should work a little better.

    $i needs an intial value and you also have to include the "$b =" in the loop. Otherwise it never changes and you have an endless loop.

    Hope that makes sense.
     
  5. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    or use it as pi().

    PHP:
    $circleARadius 10;
    $circumA pow($circleARadius,2) * pi();
     
  6. makavelimx

    makavelimx Guest

    with ryan's i got 0 as an answer

    the answer's 11.5..... may be that'd help

    *ps reply thanks
     
  7. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    i know his logic is wrong, im working on it right now ;) im kinda at work ATM so it will take a few mins
     
  8. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    in ur function you have b-a, but in your explination you have a-b.

    here is a-b, and i get 7.2 for an answer
    PHP:
     <?php
        
    /* setting initial variable values */
        
    $circleA 100 pi();
        
    $circleB 0;

        
    /* running the loop till value is found */
        
    for($c=0; ($circleA-$circleB)>=($circleA/2); $c+=0.1){
            
    $circleB pow($c,2) * pi();
        }
        
        
    /* printing the found value */
        
    echo $c;
    ?> 

    that is the code for b-a, and i get 12.4 for an answer
    PHP:
     <?php
        
    /* setting initial variable values */
        
    $circleA 100 pi();
        
    $circleB 0;

        
    /* running the loop till value is found */
        
    for($c=0; ($circleB-$circleA)<=($circleA/2); $c+=0.1){
            
    $circleB pow($c,2) * pi();
        }
        
        
    /* printing the found value */
        
    echo $c;
    ?> 
     
  9. makavelimx

    makavelimx Guest

    sorry, it was b-a, it was a typo

    http://img281.imageshack.us/img281/1777/wow5ym.jpg

    here's a diagram

    $b is the big circle
    $a is the little circle

    given: the intersection of $b and $a is HALF of $a

    I need to find the red lines $i, which is the radius


    the answer is 11.5..... with a lot of decimals after, thats what my teacher said
     
  10. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    yeah i suppose that works a little better... :hsugh:

    I'm at work too and didn't want to spend too much time on it so I didn't check into his stuff.
     
  11. makavelimx

    makavelimx Guest

    weird... cuz the teacher said the answer was 11.5....

    are u sure everythings rihgt?
     
  12. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    I was talking about him fixing my code, my posts are just getting there too late.

    Also, the link to the photo you gave doesn't work.
     
  13. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    yes it does :mamoru:


    i have a feeling your prof was wrong. 12.25 works

    PHP:
     <?php
        
    /* setting initial variable values */
        
    $circleA 100 pi();
        
    $circleB 0;

        
    /* running the loop till value is found */
        
    for($c=0; ($circleB-$circleA)<=($circleA/2); $c+=0.001){
            
    $circleB pow($c,2) * pi();
        }
        
    /* printing the found value */
        
    echo number_format($c,2,'.',',');
    ?> 
     
  14. makavelimx

    makavelimx Guest

    http://www.imagexoom.com/uploads/wow_copy2.jpg


    well here's the backgroudn to the problem, maybe itll help

    there's an ant that is tied to a leash ($i, the red lines) it eats EXACTLY half of the pizza (pink circle) because the leash causes a restriction

    I need to find the length of the leash $i
     
  15. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    it is 12.25, i just worked the problem out by hand :squint:
     
  16. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    lol works in firefox not IE, take that IE lovers
     

Share This Page