3-1-4 «Tabulation d'une fonction» - Script PHP

Initiation à la programmation avec le langage PHP, §3 Sous-programmes et tableaux

Tabulation de la fonction f(x) = 4*x4/(1+x6) sur l'intervalle [0, 2].

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>Tabulation d'une fonction</title>
<style>
table, td, th { border: 1px solid black; }
table { border-collapse: collapse; width:400px; }
td { text-align:right; }
</style>
</head>
<body>
<?php
/*
	Données
*/
$a=0;
$b=2;
function f($x){
	return 4*pow($x,4)/(1 + pow($x,6));
}
$n=20; /* Nombre d'intervalles partiels 
			= (Nombre de points) - 1 	*/
/*
	Tabulation de la fonction f
	sur l'intervalle [a, b]
*/
echo "<p><b>Tabulation de la fonction <i>f</i>
	sur l'intervalle [".$a.", ".$b."]</b></p>";
echo '<table>';
$h=($b-$a)/$n;
for($i=0; $i <= $n; $i++){
	$x=$a + $i*$h;
	$y=f($x);
	echo '<tr><td>'
		.number_format($x, 3, '.', ' ')
		.'</td><td>'
		.number_format($y, 9, '.', ' ')
		.'</td></tr>';
}
echo "</table>";
?>
</body>
</html>

Contact |  Accueil   >   PHP   >   Initiation