I am trying a solve a question. When I run this code I achieved what did I want.(.8372e-03 1.8372e-06 1.8372e-09)
truncation.error <- function(f, x) {
steps <- c(0.1, 0.01, 0.001)
n <- length(steps)
fdx1 <- vector(length = n)
for (h in 1:n) {
fdx1[h] <- exp(2.4)*steps[h]^3/6
}
return(fdx1)
}
for (i in 2.4) {
print(truncation.error(f, x))}
However when I write in data.frame format like it the output for truncation.error is 0-0-0. why the output changed? Any idea? and how can I fixed this problem. I want to see true answer which I achieved in above. ;
colnames(approx.df) <- c('Actual Values', 'Central Difference Approx', 'Central Differences Error', "truncation error")
approx.df```
Original question is [ [1]: https://i.sstatic.net/hmO3I.png][1]
How can I solve this problem or where am I making mistake? Thanks a lot.
[1]: https://i.sstatic.net/hmO3I.png
change f <- expression(exp(x)) it to f <- as.expression(exp(x))
. your error will be gone
and Mistake you are doing is you are not defining these things actual, central.approx, actual - central.approx where are these variabes saved or defined in your code?