PDA

View Full Version : Solving Quadratics with PHP

Moonbat
07-08-2008, 11:06 AM
Well, seeing how the new school year (for me) is approaching, I'm bored, and I suck at math. So I'm just gonna write up a few things in PHP to solve certain math problems for myself. Here is a simple quadratic equation solver.

<?php
/****************************
* Equation Solver *
* Written By Moonbat *
* July 7, 2008 *
****************************/

{
echo "You provided: <b>a = \$a | b = \$b | c = \$c </b><br><br>";
\$twoa = 2 * \$a;
\$negb = 0 - \$b;
\$discriminant = (\$b * \$b) - (4 * \$a * \$c);
\$sqrtdiscriminant = sqrt(\$discriminant);
\$finalanswerone = (\$negb + \$sqrtdiscriminant) / \$twoa;
\$finalanswertwo = (\$negb - \$sqrtdiscriminant) / \$twoa;

echo "Solution #* (adding then dividing): ";
echo "<br>";
echo "Solution #2 (subtracting then dividing): ";
}
echo "<hr>";
}

\$htmlone = "<html>
<body>
<center>This is a handy script to solve quadratic equations<br>
Use the subtraction sign (-) to indicate a number is negative<br>
If NAN is given as a solution, it indicates that the solution couldn't be expressed as a number</center>
<br>
<center>
<b>Values</b>