[R] newton.method
Ravi Varadhan
rvaradhan at jhmi.edu
Thu Jul 29 17:25:34 CEST 2010
Oops, it should have been:
ans <- multiStart(par=p0.mat, fn=f)
ans$par
Ravi.
____________________________________________________________________
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University
Ph. (410) 502-2619
email: rvaradhan at jhmi.edu
----- Original Message -----
From: Ravi Varadhan <rvaradhan at jhmi.edu>
Date: Thursday, July 29, 2010 11:22 am
Subject: Re: [R] newton.method
To: Dennis Murphy <djmuser at gmail.com>
Cc: r-help at r-project.org, sammyny <sjain at caa.columbia.edu>
> Yes, there are two roots. Try this to get the 2 roots:
>
> require(BB)
>
> p0.mat <- matrix(rnorm(10), 10, 1) # 10 random starting values
>
> ans <- multiStart(par=p0, fn=f)
>
> ans$par
>
>
> You can see that the 2 roots are -2.438285 and 7.419378.
>
>
> Hope this helps,
>
> Ravi.
> ____________________________________________________________________
>
> Ravi Varadhan, Ph.D.
> Assistant Professor,
> Division of Geriatric Medicine and Gerontology
> School of Medicine
> Johns Hopkins University
>
> Ph. (410) 502-2619
> email: rvaradhan at jhmi.edu
>
>
> ----- Original Message -----
> From: Dennis Murphy <djmuser at gmail.com>
> Date: Thursday, July 29, 2010 8:28 am
> Subject: Re: [R] newton.method
> To: sammyny <sjain at caa.columbia.edu>
> Cc: r-help at r-project.org
>
>
> > Hi:
> >
> > Interesting. Try the following; f is copied and pasted directly
> from
> > your
> > e-mail:
> >
> > f <- function(x) 2.5*exp(-0.5*(2*0.045 - x)) + 2.5*exp(-0.045) +
> > 2.5*exp(-1.5*x) - 100
> > curve(f, -3, 8) # plot it in a localized region
> > abline(0, 0, lty = 2)
> >
> > There are two places where the function crosses the x-axis, but
> not where
> > you were expecting. The graph suggests one root between -3 and -2
> and
> > another between 7 and 8: Note that uniroot() takes an object of class
> > function as its first argument and a search interval as its
> second.
> > It is
> > the R function that finds a zero of a univariate function. See
> > ?uniroot for
> > details. (And f is a function object; try class(f).)
> >
> > On Thu, Jul 29, 2010 at 1:32 AM, sammyny <sjain at caa.columbia.edu>
> wrote:
> >
> > >
> > > Hi,
> > > Is this method broken in R? I am using it to find roots of the following
> > > function:
> > > f(x) = 2.5*exp(-0.5*(2*0.045 - x)) + 2.5*exp(-0.045) +
> > 2.5*exp(-1.5*x) -
> > > 100
> > >
> >
> > Which method? It is never (conveniently) mentioned... Function? Package?
> >
> > >
> > > It is giving an answer of -38.4762403 which is not even close
> (f(x)
> > =
> > > 2.903809e+25 for x=-38.4762403). The answer should be around
> > 0.01-0.1. This
> > > function should converge..
> > >
> >
> > > Even for a simple function like f(x) = exp(-x) * x, it gives
> > answer as
> > > 8.89210984 for which f(x) = 0.001222392 and I set tolerance to 10^-12..
> > >
> >
> > I see handwaving and fulminating, but no code...
> >
> > >
> > > Also, is there a non graphical version of newton method? I
> looked at
> > > nleqslv
> > > but have no idea how to use it..
> > >
> >
> > > Thanks for your help.
> > >
> >
> > HTH,
> > Dennis
> >
> > > --
> > > View this message in context:
> > >
> > > Sent from the R help mailing list archive at Nabble.com.
> > >
> > > ______________________________________________
> > > R-help at r-project.org mailing list
> > >
> > > PLEASE do read the posting guide
> > >
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> >
> > PLEASE do read the posting guide
> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
>
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list