f_b1 <- function(x) -x
f_b2 <- function(x) -0.5 * x^2
integral_b <- integrate(function(x) (-x + 0.5 * x^2), lower = 0, upper = 2)
flaeche_b <- abs(integral_b$value)
cat("Fläche 3b:", round(flaeche_b, 2), "FE\n")
## Fläche 3b: 0.67 FE
x_vals_b <- seq(-2, 2, length.out = 100)
df_b <- data.frame(
x = x_vals_b,
f1 = f_b1(x_vals_b),
f2 = f_b2(x_vals_b)
)
ggplot(df_b, aes(x = x)) +
geom_line(aes(y = f1, color = "y = -x"), linewidth = 1) +
geom_line(aes(y = f2, color = "y = -0.5x²"), linewidth = 1) +
geom_area(data = subset(df_b, x >= 0 & x <= 2),
aes(y = pmax(f1, f2), fill = "Fläche"), alpha = 0.3) +
geom_area(data = subset(df_b, x >= 0 & x <= 2),
aes(y = pmin(f1, f2), fill = "Fläche"), alpha = 0.3) +
labs(title = "Aufgabe 3b",
subtitle = paste("Fläche =", round(flaeche_b, 2), "FE"),
x = "x", y = "y") +
theme_minimal() +
scale_color_manual(values = c("y = -x" = "green", "y = -0.5x²" = "purple")) +
scale_fill_manual(values = c("Fläche" = "orange")) +
theme(legend.position = "top")

f_c1 <- function(x) exp(-x)
f_c2 <- function(x) -1
integral_c <- integrate(function(x) (exp(-x) + 1), lower = 0, upper = 3)
flaeche_c <- integral_c$value
cat("Fläche 3c:", round(flaeche_c, 2), "FE\n")
## Fläche 3c: 3.95 FE
x_vals_c <- seq(-1, 3, length.out = 100)
df_c <- data.frame(
x = x_vals_c,
f1 = f_c1(x_vals_c),
f2 = f_c2(x_vals_c)
)
ggplot(df_c, aes(x = x)) +
geom_line(aes(y = f1, color = "y = e⁻ˣ"), linewidth = 1) +
geom_line(aes(y = f2, color = "y = -1"), linewidth = 1) +
geom_area(data = subset(df_c, x >= 0 & x <= 3),
aes(y = f1, fill = "Fläche"), alpha = 0.3) +
geom_area(data = subset(df_c, x >= 0 & x <= 3),
aes(y = f2, fill = "Fläche"), alpha = 0.3) +
labs(title = "Aufgabe 3c",
subtitle = paste("Fläche =", round(flaeche_c, 2), "FE"),
x = "x", y = "y") +
theme_minimal() +
scale_color_manual(values = c("y = e⁻ˣ" = "darkblue", "y = -1" = "brown")) +
scale_fill_manual(values = c("Fläche" = "lightgreen")) +
theme(legend.position = "top")

f_d1 <- function(x) -x^2
f_d2 <- function(x) sin(pi/2 * x)
integral_d <- integrate(function(x) (sin(pi/2 * x) + x^2), lower = 0, upper = 2)
flaeche_d <- integral_d$value
cat("Fläche 3d:", round(flaeche_d, 2), "FE\n")
## Fläche 3d: 3.94 FE
x_vals_d <- seq(-1, 3, length.out = 100)
df_d <- data.frame(
x = x_vals_d,
f1 = f_d1(x_vals_d),
f2 = f_d2(x_vals_d)
)
ggplot(df_d, aes(x = x)) +
geom_line(aes(y = f1, color = "y = -x²"), linewidth = 1) +
geom_line(aes(y = f2, color = "y = sin(π/2 · x)"), linewidth = 1) +
geom_area(data = subset(df_d, x >= 0 & x <= 2),
aes(y = pmax(f1, f2), fill = "Fläche"), alpha = 0.3) +
geom_area(data = subset(df_d, x >= 0 & x <= 2),
aes(y = pmin(f1, f2), fill = "Fläche"), alpha = 0.3) +
labs(title = "Aufgabe 3d",
subtitle = paste("Fläche =", round(flaeche_d, 2), "FE"),
x = "x", y = "y") +
theme_minimal() +
scale_color_manual(values = c("y = -x²" = "magenta", "y = sin(π/2 · x)" = "cyan")) +
scale_fill_manual(values = c("Fläche" = "pink")) +
theme(legend.position = "top")

cat("\n=== ERGEBNISÜBERSICHT ===\n")
##
## === ERGEBNISÜBERSICHT ===
cat(sprintf("Aufgabe 3a: %.2f FE\n", flaeche_a))
## Aufgabe 3a: 2.67 FE
cat(sprintf("Aufgabe 3b: %.2f FE\n", flaeche_b))
## Aufgabe 3b: 0.67 FE
cat(sprintf("Aufgabe 3c: %.2f FE\n", flaeche_c))
## Aufgabe 3c: 3.95 FE
cat(sprintf("Aufgabe 3d: %.2f FE\n", flaeche_d))
## Aufgabe 3d: 3.94 FE
cat("========================\n")
## ========================