1. example of NP
find sqrt(5)
let f(x) = x^2 - 5
eqation of np x(n+1) = x(n) - f[x(n)] / f'[x(n)]
in our case x(n+1) = x(n) - [x(n)^2 - 5] / [2 * x(n)]
an ugly example R code
x0 <- 2
x1 <- x0 - (x0^2 - 5) / 2 / x0
while (abs(x1 - x0) > 0.001) {
x0 <- x1
x1 <- x0 - (x0^2 - 5) / 2 / x0
}
x1
2. example of EM
similar step
find the equation
coding the equation(need to use a loop)
get the results