Maximum d'une fonction unimodale

Calcul numérique
Exemple de script PHP

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>Maximum d'une fonction unimodale</title>
</head>
<body>
<?php
/*
	Données
*/
$a=0;
$b=2;
function f($x){
	return 4*pow($x,4)/(1 + pow($x,6));
}
$d=5; // Précision = nombre de décimales
$eps=pow(10, -$d);
/*
	Calcul du maximum de f sur [a, b]
*/
echo "<p><b>Maximum de la fonction unimodale
		<i>f</i> dans l'intervalle ["
	.$a
	.", "
	.$b
	."]</b></p>";
$h=$b-$a;
while($h > $eps){
	$h3=$h/3;
	if( f($a+$h3) < f($b-$h3)){
		$a=$a+$h3;
	} else {
		$b=$b-$h3;
	}
	echo number_format(($a+$b)/2, $d+1)
	." ± "
	.number_format(($b-$a)/2, $d+1)
	."<br>";
	$h=$b-$a;
}
echo "<p>A la précision de la machine,
		la réponse est pow(2, 1/6) = "
	.pow(2,1/6)
	."</p>";
?>
</body>
</html>

Contact |  Accueil   >   PHP   >   Mathématiques numériques