PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.7.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.7.1
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
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

44 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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&nbsp;</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&nbsp;</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&nbsp;</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