Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TEKNIK BAGI
- #tol=toleransi
- bagi_dua <- function(a,b,tol,f,n)
- {
- i<-1
- selisih <- abs(a-b)
- mat_func <- NULL
- mat_a <- NULL
- mat_b <- NULL
- mat_c <- NULL
- while((selisih) >= tol) && (i<=n))
- {
- c <- (a+b)/2
- mat_c[i] <- c
- mat_a[i] <- a
- mat_func[i] <- f(c)
- if (f(a)*f(c) < 0)
- {
- b <-c
- }
- else
- {
- a <- c
- }
- selisih <- abs(a - b)
- i = i+1
- }
- matriks <- matrix(c(mat_a, mat_b,mat_c,mat_func), ncol = 4, dimnames = list(NULL, c("a","b","c","f(c)")))
- #newton_rhapson
- newton_raphson <-function (x0, tol, f ,n)
- {
- matriks <- NULL#pertemuan2 komnum - vito rizki imanda G64150093
- fungsi1 <- function(x)
- #tol=toleransi
- bagi_dua <- function(a,b,tol,f,n)
- {
- i<-1
- selisih <- abs(a-b)
- mat_func <- NULL
- mat_a <- NULL
- mat_b <- NULL
- mat_c <- NULL
- while((selisih) >= tol) && (i<=n))
- {
- c <- (a+b)/2
- mat_c[i] <- c
- mat_a[i] <- a
- mat_func[i] <- f(c)
- if (f(a)*f(c) < 0)
- {
- b <-c
- }
- else
- {
- a <- c
- }
- selisih <- abs(a - b)
- i = i+1
- }
- matriks <- matrix(c(mat_a, mat_b,mat_c,mat_func), ncol = 4, dimnames = list(NULL, c("a","b","c","f(c)")))
- #newton_rhapson
- newton_raphson <-function (x0, tol, f ,n)
- {
- matriks <- NULL
- mat_x0 <- NULL
- mat_fx <- NULL
- mat_beda <- NULL
- mat_xn <- NULL
- for(i in 1:n)
- {
- mat_x0[i] <- x0
- mat_fx[i] <- f(x0)
- turunan <- Deriv(f)
- x <- x0-(f(x0)/turunan(x0))
- mat_xn[i] <- x
- beda <- abs(x-x0)
- mat_beda[i] <- beda
- if(beda < tol)
- {
- break
- }
- x0 <- x
- }
- matriks <- matrix(c(mat_x0, mat_fx,mat_xn,mat_beda), ncol = 4, dimnames = list(NULL, ))
- matriks
- }
- fungsi <- function(x)
- {
- }
- }
- mat_x0 <- NULL
- mat_fx <- NULL
- mat_beda <- NULL
- mat_xn <- NULL
- for(i in 1:n)
- {
- mat_x0[i] <- x0
- mat_fx[i] <- f(x0)
- turunan <- Deriv(f)
- x <- x0-(f(x0)/turunan(x0))
- mat_xn[i] <- x
- beda <- abs(x-x0)
- mat_beda[i] <- beda
- if(beda < tol)
- {
- break
- }
- x0 <- x
- }
- matriks <- matrix(c(mat_x0, mat_fx,mat_xn,mat_beda), ncol = 4, dimnames = list(NULL, c("x0","fx","xn","selisih")))
- matriks
- }
- fungsi <- function(x)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement