How does PHP find the root of a quadratic equation? _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.