# Simple example: minimize f(x) = x^2 + 3
x_path <- numeric(30); x_path[1] <- 8; lr <- 0.2
for(i in 2:30) x_path[i] <- x_path[i-1] - lr * 2 * x_path[i-1]
tibble(iter=1:30, x=x_path, f=x_path^2+3) |>
ggplot(aes(iter, f)) +
geom_line(linewidth=1.2, color="#2563eb") +
geom_point(size=2, color="#1b2e4b") +
geom_hline(yintercept=3, linetype=2, color="#e63946") +
annotate("text",x=25,y=3.3,label="Minimum f=3",color="#e63946") +
labs(title="Gradient descent converging to minimum of f(x) = x² + 3",
x="Iteration", y="f(x)") + theme_di()

