Scripts
ABC-formule
Met dit script voer je gewoon a, b en c in en je krijgt de Discriminant, X1, X2, Xtop en Ytop terug. Als de discriminant nagatief is krijg je dat ook te zien. Sla het script op als abcformule.php, that's it! Als je een andere naam wil gebruiken moet je even de link aanpassen aan het eind van de tweede "if".
abcformule
<?php // Gemaakt op PHP versie 4.3.4
echo '<br><br>Gebruik bij decimalen een punt, dus geen komma!<br><br>';
if($_GET['submit'])
{
//Kijkt of er iets is ingevuld
$minb = - $_GET['b']; //-b
$tweea = 2 * $_GET['a']; // 2a
$D = pow($_GET['b'], 2) - (4 * $_GET['a'] * $_GET['c']); //D = b^2 - 4ac
$D2 = pow($D, 0.5) / $tweea; // "wortel"-D / 2a (tot de halve macht = wortel)
$xtop = $minb / $tweea; // -b / 2a (=Xtop)
$x1 = $xtop - $D2; // -b/2a - wrtl-D/2a
$x2 = $xtop + $D2; // -b/2a + wrtl-D/2a
$ytop = $_GET['a'] * pow($xtop, 2) + $_GET['b'] * $xtop + $_GET['c'] //Xtop invullen
or $_GET['a'] * pow($xtop, 2) - $_GET['b'] * $xtop - $_GET['c'];
if ($D >= 0)
{ //Alleen weergeven als D positief is
echo '<b>Discriminant:</b> ' . $D . '<br>'; //echo Discriminant
echo '<b>X<sub>1</sub>:</b> ' . $x1 . '<br>'; //echo Eerste nulpunt
echo '<b>X<sub>2</sub>:</b> ' . $x2 . '<br>'; //echo Tweede nulpunt
echo '<b>X<sub>top</sub>:</b> ' . $xtop . '<br>'; //echo Xtop
echo '<b>Y<sub>top</sub>:</b> ' . $ytop . '<br><br>'; //echo Ytop
}
else
{
echo '<b>Discriminant is negatief : ' . $D . '<br><br>
<form method="GET" action="index.php?page=abc" name="abcformule">
<input type="hidden" name="page" value="abc">
<b>a = <input type="text" name="a"><br>
b = <input type="text" name="b"><br>
c = <input type="text" name="c"><br>
<input type="submit" name="submit" value="Bereken">
<input type="reset" name="reset" value="Reset">'; //Als discriminant negatief is
}
}
else
{ //Als er nog niets is ingevuld
echo '<form method="GET" action="index.php?page=abc" name="abcformule">
<input type="hidden" name="page" value="abc">
<b>a = <input type="text" name="a"><br>
b = <input type="text" name="b"><br>
c = <input type="text" name="c"><br>
<input type="submit" name="submit" value="Bereken">
<input type="reset" name="reset" value="Reset">';
}
?>
Reacties
0