| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2017-10-29 08:39:42 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Calculation\Calculation; | 
					
						
							| 
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-01 08:48:59 +00:00
										 |  |  | require __DIR__ . '/../Header.php'; | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | ?>
 | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2017-10-01 08:48:59 +00:00
										 |  |  |         $helper->log('The equation is not quadratic'); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2017-10-01 11:07:04 +00:00
										 |  |  |         // Calculate and Display the results
 | 
					
						
							| 
									
										
										
										
											2017-10-01 08:48:59 +00:00
										 |  |  |         $helper->log('<hr /><b>Roots:</b><br />'); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $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-10-01 08:48:59 +00:00
										 |  |  |         $helper->log(Calculation::getInstance()->calculateFormula($r1Formula)); | 
					
						
							|  |  |  |         $helper->log(Calculation::getInstance()->calculateFormula($r2Formula)); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  |         $callEndTime = microtime(true); | 
					
						
							|  |  |  |         $helper->logEndingNotes(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |