osen: Prof. Dr. Suhartono, S.Si., M.Kom_196805192003121001

Fakultas: Sains dan Teknologi

Program Studi: Teknik Informatika Kelas C

library(mosaicCalc)
## Loading required package: mosaic
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## The 'mosaic' package masks several functions from core packages in order to add 
## additional features.  The original behavior of these functions should not be affected by this.
## 
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following object is masked from 'package:ggplot2':
## 
##     stat
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
##     quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
## Loading required package: mosaicCore
## 
## Attaching package: 'mosaicCore'
## The following objects are masked from 'package:dplyr':
## 
##     count, tally
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D

Untuk menghitung luas daerah di bawah kurva fungsi menggunakan integral tentu, kita dapat menggunakan konsep dasar dari integral tentu. Misalnya, jika kita memiliki fungsi f(x) pada interval [a,b] dan kita ingin menghitung luas daerah di bawah kurva tersebut, kita dapat menggunakan rumus integral tentu sebagai berikut:

Luas = ∫ batas bawah a dan batas atas b f(x)dx

Sebagai contoh, misalkan kita ingin menghitung luas di bawah kurva fungsi f(x)=x^2 dari x=0 hingga x=2.

library(pracma)
## Warning: package 'pracma' was built under R version 4.3.2
## 
## Attaching package: 'pracma'
## The following object is masked from 'package:mosaicCore':
## 
##     logit
## The following objects are masked from 'package:mosaic':
## 
##     cross, deg2rad, dot, logit, pdist, rad2deg, rand
## The following objects are masked from 'package:Matrix':
## 
##     expm, lu, tril, triu
# Install dan load package pracma
install.packages("pracma")
## Warning: package 'pracma' is in use and will not be installed
library(pracma)

# Definisikan fungsi
f <- function(x) {
  return(x^2)
}

# Tentukan batas integral
a <- 0
b <- 2

# Hitung integral menggunakan fungsi integrate()
result <- integrate(f, lower = a, upper = b)

# Buat grafik fungsi
x <- seq(0, 2, length.out = 100)
y <- f(x)

plot(x, y, type = "l", col = "blue", lwd = 2, xlab = "x", ylab = "f(x)", main = "Grafik f(x) = x^2")

# Tambahkan area di bawah kurva
polygon(c(a, x, b), c(0, y, 0), col = "skyblue")

# Tampilkan hasil integral sebagai teks pada grafik
text(1, 2, paste("Luas =", round(result$value, 2)), pos = 4, col = "red")

# Tampilkan grafik
grid()