Differensiasi 3

library(ggplot2)
polynomial_function <- function(x) 5 * x^9 + 1 * x^3 - 7 * x + 9
derivative_function <- function(x) 4 * x^7 + 3 * x - 7
x_values <- seq(-7, 8, by = 0.3)
y_original <- polynomial_function(x_values)
y_derivative <- derivative_function(x_values)
df <- data.frame(x = x_values, f_x = y_original, df_dx = y_derivative)
ggplot(df, aes(x, y)) +
  geom_line(aes(y = f_x, color = "Fungsi Asli")) +
  geom_line(aes(y = df_dx, color = "Derivatif")) +
  labs(title = "Grafik fungsi asli dan Derivatif",
       x = "x", y = "y") +
  scale_color_manual(values = c("Fungsi Asli" = "green", "Derivatif" = "orange")) +
  theme_minimal()