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

Reply via email to