[R] Comparing complex numbers

David Stoffer dsstoffer at gmail.com
Fri Jul 11 17:51:28 CEST 2008


Is there an easy way to compare complex numbers?

Here is a small example: 

>   (z1=polyroot(c(1,-.4,-.45)))
[1]  1.111111-0i -2.000000+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]  1.111111     -2.000000
[1] -8.4968e-21   8.4968e-21

>    Re(z2); Im(z2)
[1] -2 -2
[1]  0  0

Both z1 and z2 have a root of -2, but I guess Im(z1)
isn't close enough to zero for identical().

TIA.


-----
The power of accurate observation is commonly called cynicism 
by those who have not got it.  George Bernard Shaw
-- 
View this message in context: http://www.nabble.com/Comparing-complex-numbers-tp18406924p18406924.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list