PHPBuilder - Cramers Rule

# Cramers Rule

by: Craig
|
January 8, 2005

Version: 1.0.0

Type: Full Script

Category: Math Functions

Description: This is a php function that will let you quickly solve the following types of problems as well as display what was done to find the answer (all problems are algebra math level or above): Substitution Elemination

```Format:<br>
Ax + By = E<br>
Cx + Dy = F<br>
Where A-F = already known numbers preceding variables<br>
and x-y = the variables you're want to find the value of.
<?
function calc(\$a, \$b, \$c, \$d, \$e, \$f){
\$numbers = array(1 => \$a, 2 => \$b, 3 => \$c, 4 => \$d, 5 => \$e, 6 => \$f);

for(\$x=1; \$x < 7; \$x++){
\$slash = strpos(\$numbers[\$x], "/");
if(\$slash !== false){
list(\$y, \$z) = explode("/", \$numbers[\$x]);
\$numbers[\$x] = \$y / \$z;
\$numbers[\$x] = round(\$numbers[\$x], 20);
}
}
\$answer[0] = (\$numbers[1] * \$numbers[4]) - (\$numbers[3] * \$numbers[2]);
echo "\$numbers[1] \$numbers[2]<br>
\$numbers[3] \$numbers[4]<br>";

\$answer[0] = (\$numbers[5] * \$numbers[4]) - (\$numbers[6] * \$numbers[2]);
echo "\$numbers[5] \$numbers[2]<br>
\$numbers[6] \$numbers[4]<br>";

\$answer[0] = (\$numbers[1] * \$numbers[6]) - (\$numbers[3] * \$numbers[5]);
echo "\$numbers[1] \$numbers[5]<br>
\$numbers[3] \$numbers[6]<br>";

die("Invalid Input, A-D cannot equal 0");
}

}
?>
<form method=POST action="z_calc.php" name="calculator">
<table>
<tr>
<td>A:</td>
<td>
<input type="text" name="a">
</td>
<td>B:</td>
<td>
<input type="text" name="b">
</td>
<td rowspan=2>=<br>=</td>
<td>E:</td>
<td>
<input type="text" name="e">
</td>
</tr>
<tr>
<td height="26">C:</td>
<td>
<input type="text" name="c">
</td>
<td>D:</td>
<td>
<input type="text" name="d">
</td>
<td>F:</td>
<td>
<input type="text" name="f">
</td>
</tr>
<tr>
<td colspan=7 align="center">
<input type="submit" name="submit" value="Submit">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
<?
if(isset(\$_POST['submit'])){
calc(\$_POST['a'], \$_POST['b'], \$_POST['c'], \$_POST['d'], \$_POST['e'], \$_POST['f']);
}
?>```

Comment and Contribute

## Your comment has been submitted and is pending approval.

Author:
Craig

Comment:

Comment:

(Maximum characters: 1200). You have characters left.