- Original Message -
From: Ravi Varadhan [EMAIL PROTECTED]
To: 'James Foadi' [EMAIL PROTECTED]; r-help@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
Dear all,
I have a very small script to plot a function. Here it is:
##
sinca - function(N,th)
{
return(sin((N+0.5)*th)/sin(0.5*th))
}
plot_sinca - function(N)
{
x - seq(-5*pi,5*pi,by=pi/100)
y - rep(0,length=length(x))
for (i in 1:length(x))y[i] -
Very simple; it is your function. You need to step through and see that you
are evaluating close to zero:
x[701]
[1] 6.283185
sin((4.5*x[701]))
[1] -1.666142e-14
sin(.5*x[701])
[1] -1.653896e-15
sin((4.5*x[701]))/sin(.5*x[701])
[1] 10.07404
With numbers that small you might be losing
What value should your formula give when x is a multiple of 2*pi?
You seem to believe 9 is correct but in fact NaN is.
Element 701 of x is approximately but not exactly 2*pi: on my system
it is about 7*.Machine$double.eps different. You cannot expect sin(N*pi)
to be exactly zero for N != 0.
to 2*N+1 at 0, 2Pi, 4Pi, etc.
Still having the same problem.
J
- Original Message -
From: jim holtman
To: James Foadi
Cc: r-help@stat.math.ethz.ch
Sent: Thursday, July 05, 2007 8:44 PM
Subject: Re: [R] unexpected result in function valuation
Very simple; it is your
@stat.math.ethz.ch
Sent: Thursday, July 05, 2007 8:44 PM
Subject: Re: [R] unexpected result in function valuation
Very simple; it is your function. You need to step through and see that
you are evaluating close to zero:
x[701]
[1] 6.283185
sin((4.5*x[701]))
[1] -1.666142e-14
sin(.5*x[701])
[1
PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of James Foadi
Sent: Thursday, July 05, 2007 1:39 PM
To: r-help@stat.math.ethz.ch
Subject: [R] unexpected result in function valuation
Dear all,
I have a very small script to plot a function. Here it is:
##
sinca