Re: [R] Comparing complex numbers

2008-07-11 Thread David Stoffer
Thanks- I was hoping I wouldn't have to loop, but using abs() is better than comparing Re()s and Im()s, which was my original thought. I have to compare all the roots, so I used something like this: > for (i in 1:length(z1)) if(any(abs(z1[i]-z2[1:length(z2)])<1e-15)) > print("ouch") ... thank

Re: [R] Comparing complex numbers

2008-07-11 Thread Duncan Murdoch
On 7/11/2008 11:51 AM, David Stoffer wrote: Is there an easy way to compare complex numbers? Here is a small example: (z1=polyroot(c(1,-.4,-.45))) [1] 1.11-0i -2.00+0i (z2=polyroot(c(1,1,.25))) [1] -2+0i -2+0i x=0 if(any(identical(z1,z2))) x=99 x [1] 0 # real and im

[R] Comparing complex numbers

2008-07-11 Thread David Stoffer
Is there an easy way to compare complex numbers? Here is a small example: > (z1=polyroot(c(1,-.4,-.45))) [1] 1.11-0i -2.00+0i > (z2=polyroot(c(1,1,.25))) [1] -2+0i -2+0i > x=0 > if(any(identical(z1,z2))) x=99 >x [1] 0 # real and imaginary parts: >Re(z1); Im(z1) [1]