u <- 1.2 # Beispielwert (kann verändert werden)
f <- function(x) exp(-x)
# Punkte
O <- c(0, 0)
P <- c(u, 0)
Q <- c(u, f(u))
# Plotbereich
xmax <- max(4, u + 0.5)
xs <- seq(0, xmax, length.out = 400)
plot(xs, f(xs), type = "l", lwd = 2,
xlab = "x", ylab = "y",
main = expression(paste("Graph von ", f(x)==e^{-x}, " und Dreieck OPQ")))
# Achsenlinien
abline(h = 0, v = 0, col = "grey70")
# Gerade x = u
abline(v = u, col = "steelblue", lwd = 2, lty = 2)
# Dreieck einzeichnen
polygon(x = c(O[1], P[1], Q[1]), y = c(O[2], P[2], Q[2]),
border = "firebrick", lwd = 2, col = adjustcolor("firebrick", alpha.f = 0.15))
# Punkte markieren
points(rbind(O, P, Q), pch = 19, col = "firebrick")
text(O[1], O[2], labels = "O(0,0)", pos = 4)
text(P[1], P[2], labels = paste0("P(", u, ",0)"), pos = 1)
text(Q[1], Q[2], labels = bquote(Q(.(u), e^{-.(u)})), pos = 4)

A <- function(u) 0.5 * u * exp(-u)
us <- seq(0, 8, length.out = 400)
plot(us, A(us), type = "l", lwd = 2, col = "darkgreen",
xlab = "u", ylab = "A(u)",
main = expression(paste("Flächeninhalt ", A(u)==frac(1,2)*u*e^{-u})))
abline(h = 0, col = "grey70")

u_star <- 1
A_max <- A(u_star)
A_max
## [1] 0.1839397
plot(us, A(us), type = "l", lwd = 2, col = "darkgreen",
xlab = "u", ylab = "A(u)",
main = "A(u) mit Maximum")
points(u_star, A_max, pch = 19, col = "red")
text(u_star, A_max, labels = bquote("Maximum bei u=1: " ~ A==frac(1,2*e)), pos = 4)
abline(v = u_star, lty = 2, col = "red")

f <- function(x) exp(-x)
# Punkte
O <- c(0, 0)
P <- c(u, 0)
Q <- c(u, f(u))
# Plotbereich automatisch sinnvoll wählen
xmax <- max(4, u + 0.8)
xs <- seq(0, xmax, length.out = 400)
plot(xs, f(xs), type = "l", lwd = 2,
xlab = "x", ylab = "y",
main = bquote("Graph von " ~ f(x)==e^{-x} ~ " und Dreieck bei u=" ~ .(u)))
abline(h = 0, v = 0, col = "grey70") # Achsen
abline(v = u, col = "steelblue", lwd = 2, lty = 2) # Gerade x=u
# Dreieck
polygon(x = c(O[1], P[1], Q[1]),
y = c(O[2], P[2], Q[2]),
border = "firebrick", lwd = 2,
col = adjustcolor("firebrick", alpha.f = 0.15))
points(rbind(O, P, Q), pch = 19, col = "firebrick")
text(O[1], O[2], labels = "O(0,0)", pos = 4)
text(P[1], P[2], labels = bquote(P(.(u), 0)), pos = 1)
text(Q[1], Q[2], labels = bquote(Q(.(u), e^{-.(u)})), pos = 4)
