# [R] (no subject)

Linlin Yan yanlinlin82 at gmail.com
Sat May 16 16:50:35 CEST 2009

```On Sat, May 16, 2009 at 12:05 PM, Debbie Zhang <debbie0621 at hotmail.com> wrote:
>
> Dear R users,
>
> Does anyone know how to write a function involving derivative?
>
> i.e. I want to implementing Newton's method in R, so my function is something like
>
> x<- x-y/y'
>
> I am not sure how to write y' in my function. Can anyone help?
>
>
>
> In addition, if I want to implementing newton's method several times, what code should I use?
>
> Currently, I use the following code.
>
>
>
> <-1
Is this line "x <- 1"?

>> for (i in 1:20){
> + x<-x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3)}
>> x
> [1] 1.843734
>
> However, when I typed in the following code, I would yield the same answer.
> <-1
And is this line "x <- 1", too?

>> for (i in 1:1){
> + x<-x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3)}
>> x
> [1] 1.843734

What I got is like this:

> x <- 1; for (i in 1:20) { x <- x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3); }; x
[1] 1.843734
> x <- 1; for (i in 1:1) { x <- x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3); }; x
[1] 2.5

There are different!

>
> Can anyone suggest me what the problem is?
>
> Thanks so much.
>
> Debbie
> _________________________________________________________________
> View photos of singles in your area Click Here
>
> au%2Fsearch%2Fsearch%2Easpx%3Fexec%3Dgo%26tp%3Dq%26gc%3D2%26tr%3D1%26lage%3D18%26uage%3D55%26cl%3D14%26sl%3D0%26dist%3D50%26po%3D1%26do%3D2%26trackingid%3D1046138%26r2s%3D1&_t=773166090&_r=Hotmail_Endtext&_m=EXT
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>

```