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