How does PHP find the root of a quadratic equation ?. Today, someone has a mathematical question: 4x + 1x2. how much is x. Converting the equation, 4x2 + 12x, and then 4x2 + 2x + 10, is actually a problem of the unary quadratic equation. For a long time, no one has a mathematical problem today. 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.
0 two different root if ($ flg> 0) {$ x [0] = (0-$ B) + sqrt ($ flg)/2/$; $ 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"Root:
"; Print_r ($ root); echo""; ?>
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)
Bytes. 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. Not long...