Advertisement
Guest User

aaaaa

a guest
Feb 19th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. fungsi <- function (x){
  2. exp(x)
  3. }
  4.  
  5. bagi_dua <- function(a,b,tol,f,n){
  6. i <- 1
  7. selisih <-abs(a-b)
  8. mat_func <- NULL
  9. mat_b <- NULL
  10. mat_a <-NULL
  11. mat_c<-NULL
  12. while((selisih>=tol)&&(i<=n)){
  13. c <- (a+b)/2
  14. mat_c[i] <- c
  15. mat_a[i] <- a
  16. mat_b[i] <- b
  17. mat_func[i] <- f(c)
  18. if (f(a)*f(b)<0){
  19. b<-c
  20. }
  21. else{
  22. a<-c
  23. }
  24. selisih <abs(a-b)
  25. i=i+1
  26. }
  27. matrix <- matrix(c(mat_a, mat_b, mat_c, mat_func), ncol = 4, dimnames = list(NULL, c("a", "b", "c", "f(c)")))
  28. matrix
  29. }
  30. bagi_dua(0,2,0.0001,fungsi,20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement