Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1.  
  2. #TEKNIK BAGI
  3. #tol=toleransi
  4. bagi_dua <- function(a,b,tol,f,n)
  5. {
  6. i<-1
  7. selisih <- abs(a-b)
  8. mat_func <- NULL
  9. mat_a <- NULL
  10. mat_b <- NULL
  11. mat_c <- NULL
  12. while((selisih) >= tol) && (i<=n))
  13. {
  14. c <- (a+b)/2
  15. mat_c[i] <- c
  16. mat_a[i] <- a
  17. mat_func[i] <- f(c)
  18. if (f(a)*f(c) < 0)
  19. {
  20. b <-c
  21. }
  22. else
  23. {
  24. a <- c
  25. }
  26. selisih <- abs(a - b)
  27. i = i+1
  28. }
  29. matriks <- matrix(c(mat_a, mat_b,mat_c,mat_func), ncol = 4, dimnames = list(NULL, c("a","b","c","f(c)")))
  30.  
  31.  
  32.  
  33.  
  34. #newton_rhapson
  35. newton_raphson <-function (x0, tol, f ,n)
  36. {
  37. matriks <- NULL#pertemuan2 komnum - vito rizki imanda G64150093
  38.  
  39. fungsi1 <- function(x)
  40.  
  41. #tol=toleransi
  42. bagi_dua <- function(a,b,tol,f,n)
  43. {
  44. i<-1
  45. selisih <- abs(a-b)
  46. mat_func <- NULL
  47. mat_a <- NULL
  48. mat_b <- NULL
  49. mat_c <- NULL
  50. while((selisih) >= tol) && (i<=n))
  51. {
  52. c <- (a+b)/2
  53. mat_c[i] <- c
  54. mat_a[i] <- a
  55. mat_func[i] <- f(c)
  56. if (f(a)*f(c) < 0)
  57. {
  58. b <-c
  59. }
  60. else
  61. {
  62. a <- c
  63. }
  64. selisih <- abs(a - b)
  65. i = i+1
  66. }
  67. matriks <- matrix(c(mat_a, mat_b,mat_c,mat_func), ncol = 4, dimnames = list(NULL, c("a","b","c","f(c)")))
  68.  
  69.  
  70.  
  71.  
  72. #newton_rhapson
  73. newton_raphson <-function (x0, tol, f ,n)
  74. {
  75. matriks <- NULL
  76. mat_x0 <- NULL
  77. mat_fx <- NULL
  78. mat_beda <- NULL
  79. mat_xn <- NULL
  80. for(i in 1:n)
  81. {
  82. mat_x0[i] <- x0
  83. mat_fx[i] <- f(x0)
  84. turunan <- Deriv(f)
  85. x <- x0-(f(x0)/turunan(x0))
  86. mat_xn[i] <- x
  87. beda <- abs(x-x0)
  88. mat_beda[i] <- beda
  89. if(beda < tol)
  90. {
  91. break
  92. }
  93. x0 <- x
  94. }
  95. matriks <- matrix(c(mat_x0, mat_fx,mat_xn,mat_beda), ncol = 4, dimnames = list(NULL, ))
  96. matriks
  97. }
  98.  
  99. fungsi <- function(x)
  100. {
  101.  
  102. }
  103.  
  104. }
  105. mat_x0 <- NULL
  106. mat_fx <- NULL
  107. mat_beda <- NULL
  108. mat_xn <- NULL
  109. for(i in 1:n)
  110. {
  111. mat_x0[i] <- x0
  112. mat_fx[i] <- f(x0)
  113. turunan <- Deriv(f)
  114. x <- x0-(f(x0)/turunan(x0))
  115. mat_xn[i] <- x
  116. beda <- abs(x-x0)
  117. mat_beda[i] <- beda
  118. if(beda < tol)
  119. {
  120. break
  121. }
  122. x0 <- x
  123. }
  124. matriks <- matrix(c(mat_x0, mat_fx,mat_xn,mat_beda), ncol = 4, dimnames = list(NULL, c("x0","fx","xn","selisih")))
  125. matriks
  126. }
  127.  
  128. fungsi <- function(x)
  129. {
  130.  
  131. }
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement