exedat Posted February 19, 2011 Share Posted February 19, 2011 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... Quote Link to comment Share on other sites More sharing options...
silkfire Posted February 20, 2011 Share Posted February 20, 2011 Your $kissi variable is null (not defined) so you can't use it until you have given it a value; Quote Link to comment Share on other sites More sharing options...
btherl Posted February 23, 2011 Share Posted February 23, 2011 What exactly are you trying to do? Are you trying to solve the equation for r? Quote Link to comment Share on other sites More sharing options...
btherl Posted February 23, 2011 Share Posted February 23, 2011 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 Quote Link to comment Share on other sites More sharing options...
exedat Posted February 27, 2011 Author Share Posted February 27, 2011 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 i'm so wondering wolframalpha how is calculate and get result ... Quote Link to comment Share on other sites More sharing options...
btherl Posted February 28, 2011 Share Posted February 28, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.