Universitas : Universitas Islam Negeri Maulana Malik Ibrahim Malang
Jurusan : Teknik Informatika
Persamaan linear adalah persamaan aljabar yang setiap sukunya mengandung konstanta atau hasil kali konstanta dengan variabel tunggal. Persamaan non-linier dapat diartikan sebagai persamaan yang tidak mengandung syarat seperti persamaan linier sehingga persamaan non-linier dapat merupakan:
-Persamaan yang memiliki pangkat selain satu (misal: x^2)
-Persamaan yang mempunyai produk dua variabel (misal: xy)
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 bantuan fungsi root_fpi(). Berikut adalah sintaks yang digunakan:
root_secant(function(x){x-exp(-x)}, x=0)
## $`function`
## function(x){x-exp(-x)}
## <bytecode: 0x00000000151ef280>
##
## $root
## [1] 0.5671433
##
## $iter
## [1] 6
Soal 1
(x+2)^2 (x-1)^4 (x+5)
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: 0x0000000015d9ba30>
##
## $root
## [1] 0.9999996
##
## $iter
## [1] 72
soal 2
6x^4 + 11x^3 - 56x^2 - x + 60
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: 0x00000000150a1440>
##
## $root
## [1] 1.5
##
## $iter
## [1] 8
soal 3
root_secant(function(x){6(x^4) + 11(x^3) - 56*(x^2) - x + 60}, x=0.6)
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: 0x0000000015ca4330>
##
## $root
## [1] 0
##
## $iter
## [1] 2
soal 4
7x - 1 < 2x + 3
root_secant(function(x){7*x - 1 - 2*x + 3}, x=0)
## $`function`
## function(x){7*x - 1 - 2*x + 3}
## <bytecode: 0x000000001496f4e0>
##
## $root
## [1] -0.4
##
## $iter
## [1] 2