Mata Kuliah : Kalkulus

Lembaga : Universitas Islam Negeri Maulana Malik Ibrahim Malang

Prodi : Teknik Informatika

SOAL-SOAL

1. Temukan akar persamaan dari persamaan non-linear f(x)=x^3-2x+2 menggunakan metode terbuka dengan x0=0 dan x0 = 1/2!

Penyelesaian

Metode secant pada Rstudio

Fungsi root_secant() merupakan fungsi yang penulis buat untuk melakukan iterasi menggunakan metode Secant. Berikut merupakan sintaks dari fungsi tersebut:

root_secant <- function(f, x, tol=1e-7, N=100){
  iter <- 0 
  
  xold <- x 
  
  fxold <- f(x)
  
  x <- xold+10*tol 
  
  while(abs(x-xold)>tol){
    iter <- iter+1
    if(iter>N) 
      stop("No solutions found")
    
    fx <- f(x) 
    xnew <- x - fx*((x-xold)/(fx-fxold))
    xold <- x 
    fxold <- fx 
    x <- xnew 
  }
  
  root<-xnew 
  return(list(`function`=f, root=root, iter=iter))
  
}

Penyelesaian Soal f(x)= x^3+2*x+2 , dengan x =0 adalah sebagai berikut:

root_secant(function(x){x^3+2*x+2}, x=0)
## $`function`
## function(x){x^3+2*x+2}
## <bytecode: 0x0000000010e4fa58>
## 
## $root
## [1] -0.770917
## 
## $iter
## [1] 7
$`function`
## function(x){x^3+2*x+2} 
## <bytecode: 0x00000000153024c0> 
##
## $root
## [1] -0.770917 
## 
## $iter
## [1] 7

Penyelesaian soal f(x)= x^3+2*x+2 , dengan x =1/2 adalah sebagai berikut

root_secant(function(x){x^3+2*x+2}, x=1/2)
## $`function`
## function(x){x^3+2*x+2}
## <bytecode: 0x00000000117ec5c8>
## 
## $root
## [1] -0.770917
## 
## $iter
## [1] 7
$`function`
## function(x){x^3+2*x+2}
## <bytecode: 0x000002d8d43ac2c0>
##
## $root
## [1] -0.770917
##
## $iter
## [1] 7

Menampilkan grafik dari fungsi f(x) diatas

# membuat vektor data
        x <- c(-5:1); y <- x^3+2*x+2

        # membagi jendela grafik menjadi 1 baris dan 1 kolom
        par(mform=c(1,1))
## Warning in par(mform = c(1, 1)): "mform" is not a graphical parameter
        # output
        plot(x, y, type= "l")

2. Temukan akar persamaan dari persamaan f(x)=sin(x)/x dengan rentang pencarian x=0,5 dan x=1!

Penyelesaian

Penyelesaian soal f(x)= sin(x)/x, dengan x =0 adalah sebagai berikut:

root_secant(function(x){sin(x)/x}, x=1)
## $`function`
## function(x){sin(x)/x}
## <bytecode: 0x0000000010e98bc0>
## 
## $root
## [1] 3.141593
## 
## $iter
## [1] 8
##$`function`
## function(x){sin(x)/x}
## <bytecode: 0x000000154db010>
##
## $root
## [1] 3.141593
##
## $iter
## [1] 8

Penyelesaian soal f(x)= x^3+2*x+2 , dengan x =1/2 adalah sebagai berikut:

root_secant(function(x){sin(x)/x}, x=0.5)
## $`function`
## function(x){sin(x)/x}
## <bytecode: 0x000000001177ba68>
## 
## $root
## [1] 6.283185
## 
## $iter
## [1] 7
$`function`
## function(x){sin(x)/x}
## <bytecode: 0x0000000147d43a8>
##
## $root
## [1] 6.283185
##
## $iter
## [1] 7

Menampilkan grafik dari fungsi f(x) diatas

# membuat vektor data
        x <- c(0.5:1); y <- sin(x)/x
   
        # membagi jendela grafik menajdi 1 bari dan 1 kolom
        par(mfrow=c(1,1))
        
        # output
        plot(x, y, type="l")

3. Hitung integral fungsi f(x)=sin2(x) pada domain x∈[0,π]

penyelesaian

trapezoid <- function(ftn, a, b, n = 100) {
         h <- (b-a)/n 
         x.vec <- seq(a, b, by = h)
         f.vec <- sapply(x.vec, ftn) # ftn(x.vec)
         Trap <- h*(f.vec[1]/2 + sum(f.vec[2:n]) + f.vec[n+1]/2) 
         return(Trap) 
}

mendefinisikan fungsi f(x)f(x)

f <- function(x){
      sin(x)^2 
      }

Menghitung integral menggunakan trapezoid dengan pemisalan n=6

trapezoid(f,0,pi,n = 6)
## [1] 1.570796
## [1] 1.570796
trapezoid(f,0,pi,n = 6)
## [1] 1.570796
## [1] 1.570796

Menampilkan grafik dari fungsi f(x)

# membuat vektor data
        x <- c(-5:1); y <- sin(x)^2
        # membagi jendela grafik menajdi 1 baris dan 1 kolom
        par(mfrow=c(1,1)) 
        
        # output 
        plot(x, y, type="l")