Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fungsi <- function (x){
- exp(x)
- }
- bagi_dua <- function(a,b,tol,f,n){
- i <- 1
- selisih <-abs(a-b)
- mat_func <- NULL
- mat_b <- NULL
- mat_a <-NULL
- mat_c<-NULL
- while((selisih>=tol)&&(i<=n)){
- c <- (a+b)/2
- mat_c[i] <- c
- mat_a[i] <- a
- mat_b[i] <- b
- mat_func[i] <- f(c)
- if (f(a)*f(b)<0){
- b<-c
- }
- else{
- a<-c
- }
- selisih <abs(a-b)
- i=i+1
- }
- matrix <- matrix(c(mat_a, mat_b, mat_c, mat_func), ncol = 4, dimnames = list(NULL, c("a", "b", "c", "f(c)")))
- matrix
- }
- bagi_dua(0,2,0.0001,fungsi,20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement