I made this test FT=.[:+/+*[:UM# NB. the Fourier Transform
FT FT i.5 NB. No rounding. 4.44e_16j_9.99e_16 1j_2.78e_16 2j_3.33e_16 3j2.22e_16 4j2.22e_16 ]&.(1e6j1e6&+) FT FT i.5 NB. the Bo Jacoby rounding method 0 1 2 3 4 (**|)&.+. FT FT i.5 NB. the Cliff Reiter roundingmethod 0 1 2 3 4 (**|) FT FT i.5 NB. the Raul Miller rounding method 0 1j_2.78e_16 2j_3.33e_16 3j2.22e_16 4j2.22e_16 The Cliff Reiter method seems to be the simpler of the ones that work. Thank you everybody! - Bo >________________________________ > Fra: Raul Miller <rauldmil...@gmail.com> >Til: Programming forum <programming@jsoftware.com> >Sendt: 21:51 onsdag den 2. maj 2012 >Emne: Re: [Jprogramming] rounding complex numbers > >That's an interesting approach. > >But I think that the conjugates are unnecessary here: > > UM=.%:%~_1^]%~[:+:[:*/~i. > U=.n+/ .*+n=.UM 3 > (**|) U >1 0 0 >0 1 0 >0 0 1 > >Also, this only deals with the case where the sign is zero. So, it >does nothing for > j./1 2 o. 0.5p1 >1j6.12323e_17 > >-- >Raul > >On Wed, May 2, 2012 at 3:34 PM, Cliff Reiter <reit...@lafayette.edu> wrote: >> There is also >> (**|)&.+.u >> 1 0 0 >> 0 1 0 >> 0 0 1 >> >> >> On 5/2/2012 6:11 AM, Bo Jacoby wrote: >>> Hello J'ers >>> >>> Even if a complex number is actually real it may display nonzero imaginary >>> part because of round-off errors. Adding and subtracting 1e6j1e6 removes >>> the round-off error, but is there a better or more general solution? >>> >>> UM=.%:%~_1^]%~[:+:[:*/~i. NB. Unitary Matrix generator >>> >>> rd=.]&.(1e6j1e6&+) NB. round-off cleaner >>> >>> u=.n+/ .*+n=.UM 3 NB. unit matrix >>> >>> u NB. ugly display >>> 1 _2.78e_17j_1.11e_16 1.11e_16j_2.22e_16 >>> _2.78e_17j1.11e_16 1 _2.78e_17j_1.11e_16 >>> 1.11e_16j2.22e_16 _2.78e_17j1.11e_16 1 >>> >>> rd u NB. nice display >>> 1 0 0 >>> 0 1 0 >>> 0 0 1 >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >>> >> >> -- >> Clifford A. Reiter >> Lafayette College, Easton, PA 18042 >> http://webbox.lafayette.edu/~reiterc/ >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >---------------------------------------------------------------------- >For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm