Today, someone has a math question: 4x + 1/x = 2. How much is x. Convert the equation to 4x2 + 1 = 2x, and then 4x2-2x + 1 = 0, which is actually a problem with the quadratic equation of one element. I haven't completed these things for a long time, and I 've got to go back to my high school teacher in mathematics. Fortunately, I will write a program. Next I will use the program to find the root of this equation.
<? // Ax * x bx c = 0; general form of the quadratic equation of a dollar // coefficient setting $ a = 2; $ B = 3; $ c = 0; echo 'mona1 quadratic equation is '; echo $. 'x2 '. '+ '. $ B. 'X '. '+ '. $ c; // root-seeking function get_root ($ a, $ B, $ c) {// put the root array $ x = 0; $ x = array (); if ($ a = 0) {if ($ B = 0) if ($ c = 0) {$ x [0] = 0; $ x [1] = "no root";} else {$ x [0] = "no root"; $ x [1] = "no root ";} else if ($ B! = 0) {$ x [0] = (0-$ c)/$ B; $ x [1] = "no root ";}} else {// flag $ flg = $ B * $ B-4 * $ a * $ c; // △> 0 two different root if ($ flg> 0) {$ x [0] = (0-$ B) + sqrt ($ flg)/2/$ a; $ x [1] = (0-$ B) -sqrt ($ flg)/2/$ a;} else if ($ flg = 0) // △= 0 two identical roots {$ x [0] = (0-$ B)/2/$ a; $ x [1] = (0-$ B) /2/$ a;} else // rootless {$ x [0] = "no root"; $ x [1] = "no root ";}} return $ x;} // verify that the Code parameter is the value of a B c set at the top. You can modify the value of $ root = array (); $ root = get_root ($, $ B, $ c); echo "<pre> root: <br> "; Print_r ($ root); echo "<pre>";?>
The program runs as follows:
Returns the root of a quadratic equation of 2x2 + 3x + 0: Array ([0] => 0 [1] =>-1.5)
Return to the initial problem. After calculation, the result is:
Returns the root of the quadratic equation 4x2 +-2x + 1: Array ([0] => no root [1] => no root)