Jump to content

help for calculating math func.


exedat

Recommended Posts

hi,this is my program but i cant find the result ®

 

<?php

function float($r) {

for ($r=0 ; ; $r++) {


$kissi =  sqrt(1+4*(pow($kissi,2))*pow($r,2))  /  sqrt( pow( (1-pow($r,2)),2)+4*pow($kissi,2)*pow($r,2)) ;

if ($kissi==0.2) {

 break;
 }

}
echo $r ;
}
?>

 

 

http://www.wolframalpha.com/input/?i=0.2+%3D+sqrt%281%2B4*%28pow%280.2%2C2%29%29*pow%28r%2C2%29%29++%2F++sqrt%28+pow%28+%281-pow%28r%2C2%29%29%2C2%29%2B4*pow%280.2%2C2%29*pow%28r%2C2%29%29

 

i find the result like wolfram alpha pls help me...

Link to comment
Share on other sites

Is this what you want?

 

<?php
float(2.93653);

function float($r) {
        while (true) {
                $kissi =  sqrt(1+4*(pow($kissi,2))*pow($r,2))  /  sqrt( pow( (1-pow($r,2)),2)+4*pow($kissi,2)*pow($r,2)) ;
                print "kissi: $kissi\n";

                if (abs($kissi - 0.2) < 0.00001) {
                        break;
                }
        }
        echo $r ;
}

 

There were a few problems - the "for" loop was resetting $r to 0, and you need to allow a small error when testing floating point numbers for equality.  Output is this:

 

kissi: 0.131178362464
kissi: 0.164754658597
kissi: 0.181082009573
kissi: 0.189658683627
kissi: 0.194298231975
kissi: 0.196842376102
kissi: 0.198247114247
kissi: 0.199025558919
kissi: 0.199457788156
kissi: 0.199698040948
kissi: 0.199831663857
kissi: 0.199906006228
kissi: 0.199947374871
kissi: 0.199970397253
kissi: 0.19998321034
kissi: 0.199990341676
2.93653

Link to comment
Share on other sites

i want calculate complex functions and get the result like wolframalpha.com but probably php cant calculate complex func.

 

i want to try calculate for example ; 0.2=x2 +3x or x2+3x=0.2 , php cant calculate this. calculate that ; x= blabla but i cant push the "x" to the left side  alone cause of x is not 1 value  :shrug:  i'm so wondering wolframalpha how is calculate and get result ...

Link to comment
Share on other sites

php can't solve equations - all it can do is follow your instructions exactly.  You can program an algorithm for solving equations in php though.  The code you wrote appears to converge on 2 for the real solutions to that equation.

 

Yes, php can't handle complex numbers natively.  You will need to either use or write a library that handles complex arithmetic.  You can google for "php complex number class", that has some results, though I don't know how good they are.

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.