Thank you! But it doesn't work: rd=: (+ - ]) 1j1 * | rd u 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
>________________________________ > Fra: Raul Miller <rauldmil...@gmail.com> >Til: Programming forum <programming@jsoftware.com> >Sendt: 14:29 onsdag den 2. maj 2012 >Emne: Re: [Jprogramming] rounding complex numbers > >Here's a more general approach: > > rd=: (+ - ]) 1j1 * | > >-- >Raul > >On Wed, May 2, 2012 at 6:11 AM, Bo Jacoby <bojac...@yahoo.dk> 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 >---------------------------------------------------------------------- >For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm