Function g(x)
g <- function(x) {
(x ^ 3 + 3) / 7
}
g(1)
## [1] 0.5714286
Fixed_PIT()
“rlist” library was used
Fixed_PIT <- function(x, es) {
i = 0
ea = 1.1 * es
x0 = x
newlist<- list()
while (ea > es) {
xi <- g(x0)
ea <- abs(xi - x0) / xi
looplist <- list(i,x0, xi, ea)
newlist <- list.append(newlist, looplist)
i=i+1
x0=xi
}
df <- as.data.frame(do.call(rbind, newlist))
list_name <- list("iteration",
"x(i)",
"x(i+1)",
"Error")
names(df) <- c(list_name)
print(df)
cat("\n", "x= ",x0,
"\n","alpha= ",round(x0,3))
}
Check the function
Fixed_PIT(2,0.00001)
## iteration x(i) x(i+1) Error
## 1 0 2 1.571429 0.2727273
## 2 1 1.571429 0.9829238 0.5987288
## 3 2 0.9829238 0.5642345 0.7420485
## 4 3 0.5642345 0.4542329 0.2421701
## 5 4 0.4542329 0.4419601 0.02776891
## 6 5 0.4419601 0.4409039 0.002395473
## 7 6 0.4409039 0.4408157 0.0002000918
## 8 7 0.4408157 0.4408084 1.666713e-05
## 9 8 0.4408084 0.4408078 1.388007e-06
##
## x= 0.4408078
## alpha= 0.441
REFRENCE
How to show the images in Rmarkdown: https://stackoverflow.com/questions/38333691/r-markdown-putting-an-image-in-the-top-right-hand-corner-of-html-and-moving-tit