[R] unexpected result in function valuation

James Foadi james.foadi at diamond.ac.uk
Fri Jul 6 10:19:43 CEST 2007


----- Original Message ----- 
From: "Ravi Varadhan" <rvaradhan at jhmi.edu>
To: "'James Foadi'" <james.foadi at diamond.ac.uk>; <r-help at stat.math.ethz.ch>
Sent: Thursday, July 05, 2007 9:37 PM
Subject: RE: [R] unexpected result in function valuation


> The problem is that you are dividing two numbers that are both very small.
> Any small imprecision in the denominator creates a big error.
>
> Here you can re-write your function using a trig identity to get accurate
> results:
>
> sinca <- function(N,th) {
> #return(sin((N+0.5)* th)/sin(0.5*th))
> return( (sin(N*th)/tan(th/2)) + cos(N*th))
> }
>
> This function works well, as you had expected.
>
> Ravi.
>

Rounding off errors and error propagation...
I forgot all about it...Sorry for wasting your time, but thanks a lot for 
your help, Brian, Jim and Ravi.

J



More information about the R-help mailing list