2016-08-31 16:15:54 +00:00
|
|
|
<?php
|
2017-05-17 22:02:17 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation;
|
|
|
|
|
2016-08-31 16:15:54 +00:00
|
|
|
require __DIR__ . '/Header.php';
|
|
|
|
?>
|
2017-03-16 15:24:43 +00:00
|
|
|
<form action="45_Quadratic_equation_solver.php" method="POST">
|
2016-08-31 16:15:54 +00:00
|
|
|
Enter the coefficients for the Ax<sup>2</sup> + Bx + C = 0
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0">
|
|
|
|
<tr><td><b>A </b></td>
|
|
|
|
<td><input name="A" type="text" size="8" value="<?php echo (isset($_POST['A'])) ? htmlentities($_POST['A']) : ''; ?>"></td>
|
|
|
|
</tr>
|
|
|
|
<tr><td><b>B </b></td>
|
|
|
|
<td><input name="B" type="text" size="8" value="<?php echo (isset($_POST['B'])) ? htmlentities($_POST['B']) : ''; ?>"></td>
|
|
|
|
</tr>
|
|
|
|
<tr><td><b>C </b></td>
|
|
|
|
<td><input name="C" type="text" size="8" value="<?php echo (isset($_POST['C'])) ? htmlentities($_POST['C']) : ''; ?>"></td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<input name="submit" type="submit" value="calculate"><br />
|
|
|
|
If A=0, the equation is not quadratic.
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
/** If the user has submitted the form, then we need to execute a calculation * */
|
|
|
|
if (isset($_POST['submit'])) {
|
|
|
|
if ($_POST['A'] == 0) {
|
|
|
|
echo 'The equation is not quadratic';
|
|
|
|
} else {
|
|
|
|
/* Calculate and Display the results * */
|
|
|
|
echo '<hr /><b>Roots:</b><br />';
|
|
|
|
|
|
|
|
$discriminantFormula = '=POWER(' . $_POST['B'] . ',2) - (4 * ' . $_POST['A'] . ' * ' . $_POST['C'] . ')';
|
2017-05-17 22:02:17 +00:00
|
|
|
$discriminant = Calculation::getInstance()->calculateFormula($discriminantFormula);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
$r1Formula = '=IMDIV(IMSUM(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . ')';
|
|
|
|
$r2Formula = '=IF(' . $discriminant . '=0,"Only one root",IMDIV(IMSUB(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . '))';
|
|
|
|
|
2017-05-17 22:02:17 +00:00
|
|
|
echo Calculation::getInstance()->calculateFormula($r1Formula) . '<br />';
|
|
|
|
echo Calculation::getInstance()->calculateFormula($r2Formula) . '<br />';
|
2016-08-31 16:15:54 +00:00
|
|
|
$callEndTime = microtime(true);
|
|
|
|
$helper->logEndingNotes();
|
|
|
|
}
|
|
|
|
}
|