Hello Everybody,

Just when I thought I was out of the hook/fork fog they pulled me back in.

I was trying to construct a verb for a covariance matrix:

http://stattrek.com/matrix-algebra/covariance-matrix.aspx

]data=. 5 3 $ 90 60 90 90 90 30 60 60 60 60 60 90 30 30 30

mean=: +/%#
mp=:  +/ . * 
covmat=: ((mp~|:)(-"1 mean))%# NB. divede by n not n-1 to comply with the 
example 

   covmat data
504 360 180
360 360   0
180   0 720

The result seems to be ok but I am confused with the verb. Isn't it a fork
with two hooks on the left and a primitive on the right

If I put a cap before the two hooks

covmat2=: ([:(mp~|:)(-"1 mean))%#

It gives the same answer

   covmat2 data
504 360 180
360 360   0
180   0 720

I can't figure out why it works whether the cap is there or not.

Esa 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to