From 4ebfe8d1b810d96c612f2e7657d6705c6cf9e1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Wed, 18 Dec 2024 11:01:37 +0100 Subject: [PATCH] fix(correct the function definition for calculating expectation): correct the function definition for calculating expectation - Corrected the function definition `fonction_esperance` to use `f(x)` instead of `(1 - x)^4`. - Added code to calculate the integral using the rectangle method. - Added code to plot the graph of the rectangle method for the integral. --- TD1/Exercice51.R | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/TD1/Exercice51.R b/TD1/Exercice51.R index 5c1635c..09f4198 100644 --- a/TD1/Exercice51.R +++ b/TD1/Exercice51.R @@ -16,8 +16,21 @@ capacite <- uniroot(function(x) F(x) - cible, lower = 0, upper = 1)$root print(capacite * 1000) # c) (Bonus) Calculer l'espérence fonction_esperance <- function (x) { - x * c * (1 - x)^4 + x * c * f(x) } esperance <- integrate(fonction_esperance, lower = 0, upper = 1)$value -print(esperance) \ No newline at end of file +print(esperance) + +# d) (Bonus) Faire avec la méthode des réctangle et tracer le graphique de la construction +n <- 15 +dx <- 1 / n +x_vals <- seq(0, 1, length.out = n) +y_vals <- f(x_vals) +integrale_rect <- sum(y_vals * dx) + +print(integrale_rect) +plot(x_vals, y_vals, type = "list", col = "blue", lwd = 2, + main = "Methode des rectangles pour l'integrale", + xlab = "x", ylab = "f(x)") +rect(x_vals[-n], 0, x_vals[-1], y_vals[-n], col = rgb(0, 0, 1, 0.2), border = NA) \ No newline at end of file