Page 1 of 1

help for calculating math func.

Posted: Fri Feb 18, 2011 9:14 pm
by exedat
hi,this is my program but i cant find the result (r)

Code: Select all

<?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. ... %2C2%29%29

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

Re: help for calculating math func.

Posted: Fri Feb 18, 2011 9:59 pm
by Jonah Bron
"can't find the result"? You mean it's incorrect? What exactly is the problem? Are you trying to calculate it out to r ~= 2.93653 ?

Re: help for calculating math func.

Posted: Fri Feb 18, 2011 10:34 pm
by exedat
Jonah Bron wrote:"can't find the result"? You mean it's incorrect? What exactly is the problem? Are you trying to calculate it out to r ~= 2.93653 ?
yes i'm trying to calculate it for "r" . and my program isnt true probably because i run the program, i am seeing blank page :( pls help me , i'm trying to calc. like wolfram alpha , how can get the result on php?

Re: help for calculating math func.

Posted: Fri Feb 18, 2011 10:38 pm
by s.dot
You won't find the result by pasting the code in the URL like that.

You have your function defined, now you need to use it... like this:

Code: Select all

echo float(8.3);
For example

Re: help for calculating math func.

Posted: Sat Feb 19, 2011 1:11 am
by McInfo
In programming languages like PHP, there are no equations; there are only expressions.

In algebra, this equation is solvable.

Code: Select all

x = 3x - 4
By subtracting 3x from both sides and dividing both sides by -2, it is revealed that x is 2.

However, in PHP, a similar statement is treated differently.

Code: Select all

$x = 3 * $x - 4;
PHP does not "solve for x". The $x on the right is not necessarily equal to the $x on the left. If $x is not given a value before this statement, its assumed value is equivalent to 0. The arithmetical operations reduce the expression on the right to -4. That number is then assigned to the $x on the left.

Whereas the algebra equation is a puzzle to be solved, the PHP statement is a set of instructions to be followed.

To solve an equation like

Code: Select all

21 = 7 * x
programmatically, you can...
  1. ...create a way to parse the symbols and "undo" the operations to isolate a single variable. In the example, the x can be isolated by dividing by 7 to undo the multiplication. Reducing the mirrored expression (21 / 7) reveals the value of x.
  2. ...brute-force potential values until both sides of the equation are equal (or close to equal). In the example, {0, 1, 2} might be tried as values of x before it is found that 3 makes both sides equal 21. You might try something like a binary search to close in on the correct answer quicker.