visualizer
/
vendor
/
phpoffice
/
phpspreadsheet
/
samples
/
Basic
/
45_Quadratic_equation_solver.php
45_Quadratic_equation_solver.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.7.1, at vendor/phpoffice/phpspreadsheet/samples/Basic/45_Quadratic_equation_solver.php
| 1 | <?php |
| 2 | use PhpOffice\PhpSpreadsheet\Calculation\Calculation; |
| 3 | |
| 4 | require __DIR__ . '/../Header.php'; |
| 5 | ?> |
| 6 | <form action="45_Quadratic_equation_solver.php" method="POST"> |
| 7 | Enter the coefficients for the Ax<sup>2</sup> + Bx + C = 0 |
| 8 | <table border="0" cellpadding="0" cellspacing="0"> |
| 9 | <tr><td><b>A </b></td> |
| 10 | <td><input name="A" type="text" size="8" value="<?php echo (isset($_POST['A'])) ? htmlentities($_POST['A']) : ''; ?>"></td> |
| 11 | </tr> |
| 12 | <tr><td><b>B </b></td> |
| 13 | <td><input name="B" type="text" size="8" value="<?php echo (isset($_POST['B'])) ? htmlentities($_POST['B']) : ''; ?>"></td> |
| 14 | </tr> |
| 15 | <tr><td><b>C </b></td> |
| 16 | <td><input name="C" type="text" size="8" value="<?php echo (isset($_POST['C'])) ? htmlentities($_POST['C']) : ''; ?>"></td> |
| 17 | </tr> |
| 18 | </table> |
| 19 | <input name="submit" type="submit" value="calculate"><br /> |
| 20 | If A=0, the equation is not quadratic. |
| 21 | </form> |
| 22 | |
| 23 | <?php |
| 24 | /** If the user has submitted the form, then we need to execute a calculation * */ |
| 25 | if (isset($_POST['submit'])) { |
| 26 | if ($_POST['A'] == 0) { |
| 27 | $helper->log('The equation is not quadratic'); |
| 28 | } else { |
| 29 | // Calculate and Display the results |
| 30 | $helper->log('<hr /><b>Roots:</b><br />'); |
| 31 | |
| 32 | $discriminantFormula = '=POWER(' . $_POST['B'] . ',2) - (4 * ' . $_POST['A'] . ' * ' . $_POST['C'] . ')'; |
| 33 | $discriminant = Calculation::getInstance()->calculateFormula($discriminantFormula); |
| 34 | |
| 35 | $r1Formula = '=IMDIV(IMSUM(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . ')'; |
| 36 | $r2Formula = '=IF(' . $discriminant . '=0,"Only one root",IMDIV(IMSUB(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . '))'; |
| 37 | |
| 38 | $helper->log(Calculation::getInstance()->calculateFormula($r1Formula)); |
| 39 | $helper->log(Calculation::getInstance()->calculateFormula($r2Formula)); |
| 40 | $callEndTime = microtime(true); |
| 41 | $helper->logEndingNotes(); |
| 42 | } |
| 43 | } |
| 44 |