[R] Computing 'exp(1e3)*0' correctly....
CHEL HEE LEE
gnustats at gmail.com
Sun Sep 2 16:38:35 CEST 2012
I very appreciate for good comments and tip regarding my question. All
postings are excellent to know when I am writing such expression in R.
Thank you so much, and my question is completely resolved from all your
postings.
On Sun, 2012-09-02 at 00:50 +0100, Rui Barradas wrote:
> Em 02-09-2012 00:10, Jeff Newmiller escreveu:
> > I disagree that this answer is "wrong". If you want a mathematically correct answer you are going to have to obtain it by applying intelligence to the algorithm in which this calculation occurred.
>
> Logarithms are the product of intelligence.
> And the standard trick to make this sort of computation.
>
> x <- 1e3
> exp(x + log(0)) # zero
>
> x <- 1e300
> exp(x + log(0)) # zero
>
> Rui Barradas
> > This is not a mailing list about numerical methods in general, so it probably isn't appropriate to pursue that conversation here.
> > ---------------------------------------------------------------------------
> > Jeff Newmiller The ..... ..... Go Live...
> > DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
> > Live: OO#.. Dead: OO#.. Playing
> > Research Engineer (Solar/Batteries O.O#. #.O#. with
> > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> > ---------------------------------------------------------------------------
> > Sent from my phone. Please excuse my brevity.
> >
> > CHEL HEE LEE <gnustats at gmail.com> wrote:
> >
> >> I have some trouble to deal the value of 'NaN'. For example,
> >>
> >>> exp(1e3)
> >> [1] Inf
> >>> exp(1e3)*0
> >> [1] NaN
> >>
> >> The correct answer should be 0 rather than NaN. I will very appreciate
> >> if anyone can share some technique to get a correct answer.
> >>
> >> ______________________________________________
> >> 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.
> > ______________________________________________
> > 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.
>
More information about the R-help
mailing list