[R] Newton-RaphsonMethod

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sun Feb 24 18:53:55 CET 2019


This list has a no homework policy.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Feb 24, 2019 at 9:22 AM malika yassa via R-help <
r-help using r-project.org> wrote:

> 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]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list