ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Quadratic2.php
Go to the documentation of this file.
1<html>
2<head>
3<title>Quadratic Equation Solver</title>
4</head>
5<body>
6<?php
7
9error_reporting(E_ALL);
10
12set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../Classes/');
13
14?>
15<h1>Quadratic Equation Solver</h1>
16<form action="Quadratic2.php" method="POST">
17Enter the coefficients for the Ax<sup>2</sup> + Bx + C = 0
18<table border="0" cellpadding="0" cellspacing="0">
19 <tr><td><b>A&nbsp;</b></td>
20 <td><input name="A" type="text" size="8" value="<?php echo (isset($_POST['A'])) ? htmlentities($_POST['A']) : ''; ?>"></td>
21 </tr>
22 <tr><td><b>B&nbsp;</b></td>
23 <td><input name="B" type="text" size="8" value="<?php echo (isset($_POST['B'])) ? htmlentities($_POST['B']) : ''; ?>"></td>
24 </tr>
25 <tr><td><b>C&nbsp;</b></td>
26 <td><input name="C" type="text" size="8" value="<?php echo (isset($_POST['C'])) ? htmlentities($_POST['C']) : ''; ?>"></td>
27 </tr>
28</table>
29<input name="submit" type="submit" value="calculate"><br />
30If A=0, the equation is not quadratic.
31</form>
32
33<?php
35if (isset($_POST['submit'])) {
36 if ($_POST['A'] == 0) {
37 echo 'The equation is not quadratic';
38 } else {
40 include 'PHPExcel/Calculation.php';
41
43 echo '<hr /><b>Roots:</b><br />';
44
45 $callStartTime = microtime(true);
46 $discriminantFormula = '=POWER('.$_POST['B'].',2) - (4 * '.$_POST['A'].' * '.$_POST['C'].')';
47 $discriminant = PHPExcel_Calculation::getInstance()->calculateFormula($discriminantFormula);
48
49 $r1Formula = '=IMDIV(IMSUM(-'.$_POST['B'].',IMSQRT('.$discriminant.')),2 * '.$_POST['A'].')';
50 $r2Formula = '=IF('.$discriminant.'=0,"Only one root",IMDIV(IMSUB(-'.$_POST['B'].',IMSQRT('.$discriminant.')),2 * '.$_POST['A'].'))';
51
52 echo PHPExcel_Calculation::getInstance()->calculateFormula($r1Formula).'<br />';
53 echo PHPExcel_Calculation::getInstance()->calculateFormula($r2Formula).'<br />';
54 $callEndTime = microtime(true);
56
57 echo '<hr />Call time for Quadratic Equation Solution was '.sprintf('%.4f',$callTime).' seconds<br /><hr />';
58 echo ' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).' MB<br />';
59 }
60}
61
62?>
63
64</body>
65<html>
$callEndTime
$callTime
$callStartTime
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
input
Definition: langcheck.php:166
font size
Definition: langcheck.php:162