Teknik Informatika
Universitas Maulana Malik Ibrahim Malang
Metode Secant merupakan perbaikan dari metode regula-falsi dan Newton Raphson, dimana kemiringan dua titik dinyatakan secara diskrit dengan mengambil bentuk garis lurus yang melalui satu titik.
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))
}
Untuk mempercepat proses iterasi kita dapat menggunakan fungsi root_secant() pada R. Berikut sintaks yang digunakan:
root_secant(function(x){x-exp(-x)}, x=0)
## $`function`
## function(x){x-exp(-x)}
## <bytecode: 0x00000000094b8338>
##
## $root
## [1] 0.5671433
##
## $iter
## [1] 6
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: 0x0000000008725cc8>
##
## $root
## [1] 0.9999996
##
## $iter
## [1] 72
root_secant(function(x){6*(x^4) + 11*(x^3) - 56*(x^2) - x + 60}, x=0.6)
## $`function`
## function(x){6*(x^4) + 11*(x^3) - 56*(x^2) - x + 60}
## <bytecode: 0x00000000095d6798>
##
## $root
## [1] 1.5
##
## $iter
## [1] 8
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: 0x0000000008764470>
##
## $root
## [1] 0
##
## $iter
## [1] 2
root_secant(function(x){7*x - 1 - 2*x + 3}, x=0)
## $`function`
## function(x){7*x - 1 - 2*x + 3}
## <bytecode: 0x0000000008d30b50>
##
## $root
## [1] -0.4
##
## $iter
## [1] 2
Suhartono.2015.Memahami Kalkulus Dasar Menggunakan Wolfram Mathematica 9.UIN Maliki Malang: Malang.