[R] Newton-RaphsonMethod

malika yassa y@@@@_m@||k@ @end|ng |rom y@hoo@|r
Sun Feb 24 14:25:24 CET 2019


HELLOplease I want to approximate the solution of the equation f(x)=x*(x-2)+log(x)=0
for that i did this program

f <- function(x){x*(x-2)+log(x)}
x <- c(1 : 2)
f(x)
h <- 1e-7
df.dx <- function(x){(f(x + h) - f(x)) / h}
df.dx(3/2);df.dx(2)
 newton <- function(f, tol = 1e-7, x0 = 3/2, N = 100){
 h = 1e-7
 i = 1; x1 = x0
 p = numeric(N)
 while (i <= N) {
 df.dx = (f(x + h) - f(x)) / h
 x1 = (x0 - (f(x0) / df.dx))
 p[1] = x1
 i = i + 1
 if (abs(x1 - x0) < tol) break
 x0 = x1
 }
 return(p[1 : (i-1)])
 }
 app <- newton(f, x0 = 3/2)

but i cann't find this approximation
please can you help me?






	[[alternative HTML version deleted]]



More information about the R-help mailing list