Universitas : UIN Maulana Malik Ibrahim Malang
Prodi : Teknik Informatika
Fakultas : Sains dan Teknologi
Dosen : Prof. Dr. SUHARTONO, M.Kom
Graphical integration visually represents the process of finding the definite integral by calculating the area under the curve.
# Function to be integrated
f <- function(x) x^2 + 2*x + 1
# Riemann sum for graphical integration
riemann_graphical_integration <- function(f, a, b, n = 10) {
delta_x <- (b - a) / n
x_values <- seq(a, b, length.out = n)
# Calculate the heights of rectangles
heights <- f(x_values)
# Plot the function
plot(x_values, heights, type = "l", col = "blue", lwd = 2, main = "Graphical Integration", xlab = "x", ylab = "y")
# Draw rectangles
for (i in 1:n) {
rect(x_values[i], 0, x_values[i + 1], heights[i], col = "skyblue", border = "black")
}
# Calculate and return the Riemann sum
sum(heights * delta_x)
}
# Interval for integration
a <- 0
b <- 8
# Compute the Riemann sum for graphical integration
riemann_sum <- riemann_graphical_integration(f, a, b, n = 10)
riemann_sum
## [1] 252.1481