help for calculating math func.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
exedat
Forum Newbie
Posts: 2
Joined: Fri Feb 18, 2011 8:51 pm
Location: Heaven

help for calculating math func.

Post 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...
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: help for calculating math func.

Post 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 ?
exedat
Forum Newbie
Posts: 2
Joined: Fri Feb 18, 2011 8:51 pm
Location: Heaven

Re: help for calculating math func.

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: help for calculating math func.

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: help for calculating math func.

Post 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.
Post Reply