PHP Classes

Quadratic equations

Recommend this page to a friend!

      PHP Equations  >  All threads  >  Quadratic equations  >  (Un) Subscribe thread alerts  
Subject:Quadratic equations
Summary:Just one root out of two is returned in quadratic equations
Messages:3
Author:Angelo
Date:2014-09-28 13:35:09
 

  1. Quadratic equations   Reply   Report abuse  
Picture of Angelo Angelo - 2014-09-28 13:35:09
I'm trying to use phpequations to solve quadratic equations with this code:

include("phpequations.class.php");
$equations = new phpequations();
$equation = "pow(x,2)+2*x-1=0";
$resolve = $equations->solve($equation);
print_r($resolve);

The problem is that $resolve[x] will return just one of the roots of the equation (0.4142).
I tried also with the following equations:
pow(x,2)=4 (returns 2)
pow(x,2)+2*x=0 (returns 0)

How can I fix this problem?

  2. Re: Quadratic equations   Reply   Report abuse  
Picture of Naveed ur Rehman Naveed ur Rehman - 2014-09-28 19:49:22 - In reply to message 1 from Angelo
This php class uses newton-raphson iterative method and therefore, it:
- works on real-roots only (no imaginary numbers)
- results in only one root of any polynomial

  3. Re: Quadratic equations   Reply   Report abuse  
Picture of Angelo Angelo - 2014-09-28 19:53:51 - In reply to message 2 from Naveed ur Rehman
Thanks for your answer.