diff --git a/Tests/Quadratic.php b/Tests/Quadratic.php new file mode 100644 index 00000000..ce4191a2 --- /dev/null +++ b/Tests/Quadratic.php @@ -0,0 +1,68 @@ + + +Quadratic Equation Solver + + + +

Quadratic Equation Solver

+
+Enter the coefficients for the Ax2 + Bx + C = 0 + + + + + + + + + + +
+
+If A=0, the equation is not quadratic. +
+ +getActiveSheet()->setCellValue('A1', $_POST['A']); + $objPHPExcel->getActiveSheet()->setCellValue('B1', $_POST['B']); + $objPHPExcel->getActiveSheet()->setCellValue('C1', $_POST['C']); + + + /** Calculate and Display the results **/ + echo '
Roots:
'; + + $callStartTime = microtime(true); + echo $objPHPExcel->getActiveSheet()->getCell('B5')->getCalculatedValue().'
'; + echo $objPHPExcel->getActiveSheet()->getCell('B6')->getCalculatedValue().'
'; + $callEndTime = microtime(true); + $callTime = $callEndTime - $callStartTime; + + echo '
Call time for Quadratic Equation Solution was '.sprintf('%.4f',$callTime).' seconds

'; + echo ' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).' MB
'; + } +} + +?> + + + diff --git a/Tests/Quadratic.xlsx b/Tests/Quadratic.xlsx new file mode 100644 index 00000000..9a094b36 Binary files /dev/null and b/Tests/Quadratic.xlsx differ diff --git a/Tests/Quadratic2.php b/Tests/Quadratic2.php new file mode 100644 index 00000000..93f28599 --- /dev/null +++ b/Tests/Quadratic2.php @@ -0,0 +1,65 @@ + + +Quadratic Equation Solver + + + +

Quadratic Equation Solver

+
+Enter the coefficients for the Ax2 + Bx + C = 0 + + + + + + + + + + +
+
+If A=0, the equation is not quadratic. +
+ +Roots:
'; + + $callStartTime = microtime(true); + $discriminantFormula = '=POWER('.$_POST['B'].',2) - (4 * '.$_POST['A'].' * '.$_POST['C'].')'; + $discriminant = PHPExcel_Calculation::getInstance()->calculateFormula($discriminantFormula); + + $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'].'))'; + + echo PHPExcel_Calculation::getInstance()->calculateFormula($r1Formula).'
'; + echo PHPExcel_Calculation::getInstance()->calculateFormula($r2Formula).'
'; + $callEndTime = microtime(true); + $callTime = $callEndTime - $callStartTime; + + echo '
Call time for Quadratic Equation Solution was '.sprintf('%.4f',$callTime).' seconds

'; + echo ' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).' MB
'; + } +} + +?> + + +