UIN MAULANA MALIK IBRAHIM MALANG,Teknik Informatika

Algoritma Metode Secant Pada RStudio

1.Definisikan f(x)f(x) dan f′(x)f′(x)

2.Tentukan nilai toleransi ee dan iterasi masimum (N)

3.Tentukan tebakan awal x0x0 dan x1x1

4.Hitung f(x0)f(x0) dan f(x1)f(x1)

5.Untuk iterasi i=1i=1 s/d NN atau |f(x)|≥e|f(x)|≥e, hitung xx menggunakan Persamaan (7.14)

6.Akar persamaan adalah nilai x yang terakhir.

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))
}
root_secant(function(x){x-exp(-x)}, x=0)
## $`function`
## function(x){x-exp(-x)}
## <bytecode: 0x0000000014d650f8>
## 
## $root
## [1] 0.5671433
## 
## $iter
## [1] 6

Berdasarkan hasil iterasi diperoleh nilai akar penyelesaian adalah x=0,5671433 dengan iterasi dilakukan sebanyak 6 kali.

LEMBAR KERJA MAHASISWA

Jawablah soal dibawah ini menggunakan metode secant pada RStudio

Cari hasil perkalian dari tiga persamaan berikut (x + 2)2(x − 1)4(x + 5). Cari faktor dari persamaan 6x4 + 11x3 − 56x2 − x + 60 Cari penyelesaian persamaan x4 − 5x3 + 3x2 + x = 0 Cari penyelesaian dari pertidaksamaan 7x – 1 < 2x + 3

1. Cari hasil perkalian dari tiga persamaan berikut (x + 2)2(x − 1)4(x + 5).

Penyelesaian:

root_secant(function(x){((x + 2)^2)*((x − 1)^4)*(x + 5)}, x=0)
## $`function`
## function(x){((x + 2)^2)*((x - 1)^4)*(x + 5
## <bytecode: 0x000000001288a578>
## 
## $root
## [1] 0.9999996
## 
## $iter
## [1] 72

2. Cari faktor dari persamaan 6x4 + 11x3 − 56x2 − x + 60

Penyelesaian:

root_secant(function(x){6*(x^4)+11*(x^3)-56*(x^2)+60}, x=0)
## $`function`
## function(x){6*(x^4)+11*(x^3)-56*(x^2)+60}
## <bytecode: 0x0000000014c37e30>
## 
## $root
## [1] 1.000008e-06
## 
## $iter
## [1] 3

3. Cari penyelesaian persamaan x4 − 5x3 + 3x2 + x = 0

Penyelesaian:

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

4. Cari penyelesaian dari pertidaksamaan 7x – 1 < 2x + 3

Penyelesaian:

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

sumber

file:///C:/Users/USER/Documents/iyan/kalkulus/buku%20matenmatika%20suhartono.pdf https://bookdown.org/moh_rosidi2610/Metode_Numerik/rootfinding.html#uniroot