Méthode de la bissectionCalcul numérique d'un zéro d'une fonction
|
|
Le bouton permet d'exécuter le script PHP.
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<meta name="robots" content="NoIndex,NoFollow">
<title>Méthode de la bissection</title>
</head>
<body>
<?php
/*
Données
*/
$a = 0;
$b = 1;
$eps = 1.e-8;
function f($x){
return (($x-4)*$x-20)*$x+1;
}
/*
Bissection
*/
echo "<p><b>Un zéro de la fonction <i>f</i>
dans l'intervalle ["
.$a
.", "
.$b
."]</b></p>";
$fa = f($a);
$fb = f($b);
if ($fa*$fb > 0) {
echo "L'hypothèse f(a)*f(b) <= 0
n'est pas satisfaite";
} else {
$c = ($a+$b)*0.5;
$d = ($b-$a)*0.5;
while ($d > $eps) {
$fc = f ($c);
if ($fa*$fc <= 0) {
$b = $c;
$fb = $fc;
} else {
$a = $c;
$fa = $fc;
}
$c = ($a+$b)*0.5;
$d = ($b-$a)*0.5;
echo number_format($c,9)." ± "
.number_format($d,9)."<br>";
}
}
echo "<p>Valeur précise à 16 chiffres
= 0.04951570905559387</p>";
?>
</body>
</html>
|
| Contact | Accueil > PHP > Mathématiques numériques |