<!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>Fonction définie par morceaux</title>
</head>
<body>
<?php
/*
Données, à exécuter avec les valeurs
$x = -3, 0.5, 3
*/
$x = 0.5;
/*
Fonction définie par morceaux
*/
if($x <= 0){
echo "<p> x = "
.$x
." appartient au morceau 1 où f(x) = 0";
$y = 0;
} elseif ($x < 1) {
echo "<p> x = "
.$x
." appartient au morceau 2 où f(x) = x^2";
$y = pow($x, 2);
} else {
echo "<p> x = "
.$x
." appartient au morceau 3 où f(x) = 2*x";
$y = 2*$x;
}
echo "<br>f("
.$x
.") = "
.$y
."</p>";
?>
</body>
</html>