From 5f5e793c0579d86b9a938cdebe8718fdb9fe83db Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Fri, 17 Sep 2010 22:46:31 +0000 Subject: [PATCH] Added Quadratic Equation Solver examples of calculation engine usage git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@61104 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Tests/Quadratic.php | 68 +++++++++++++++++++++++++++++++++++++++++++ Tests/Quadratic.xlsx | Bin 0 -> 8908 bytes Tests/Quadratic2.php | 65 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 Tests/Quadratic.php create mode 100644 Tests/Quadratic.xlsx create mode 100644 Tests/Quadratic2.php 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 0000000000000000000000000000000000000000..9a094b36226753be00671f92d2570a2d2e4575b1 GIT binary patch literal 8908 zcmeHtWl&t(wskiy!8JI+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Fy|LQfL?r-B<>b{({e1KV8f3%hWMha zHB9VvPUPNORzQ2FUd@A%xnc&K&AnsIC|{M1vkQ_{C;RKD61A@~9MbkAonbJ1!MA+8 z-Zo6v>ox>O$WE!()X_0f9rxdsv6${AxdKhlo6m@5gy8G=cM4vZq{ddlDcA=OGu%H@ z5Mpcl4+C$w_s0d(XtkcZNe0srr1e7fMOua=KSR*x&(#PJL zVfnNlH?kYOs&1~0WMqK8OAd7gKhv$9R)rNbgLwbypE%#r3@9);mcg9;?wi zAX_d>Kd!?Jl*YPxRE3BAna?zenBx`e{(|51{zt#eyNLYcD~;%Kd z8%7t~Gk_9$F6bCW1x_qw=60{>>3MajqOYxXz&?GS<(ITO4Gt|T=*|SrE#Fg3)Q+F1 zQoXoBI;-*uv58eNi{}%byLM;fdkDKYzK6bGyC%3uy%Yhk{$p_S?p{`@Fx512KNv z^}P*nyXyW0AdL5)U;kST{{N1WkN;bgpLOMJl-t$OuXmwTXDD};^{{kli4Eg{7 literal 0 HcmV?d00001 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
'; + } +} + +?> + + +