A key point that dawned on me, after reading all the helpful comments and suggestions that have come in, is that I don't need a verb- just a noun - so
   y=: 2 3 4 2 2 3  (it also works for an n,n array)

  ] u=:=i.# y
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1

and I can use u*y for different 'y''s ( as long as the # is the same) to get the desired diagonal elements with off diagonal elements 0 I want this because I want to add to the diagonal elements of a matrix. This is for a Newton Raphson based power system load flow.

Thanks to all,
Don


On 20/11/2012 8:24 AM, Roger Hui wrote:
http://www.jsoftware.com/jwiki/Essays/Identity%20Matrix : 34 different ways
to generate the identity matrix of order n; the first is =@i. and the last
is _&q:@p:@i.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


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

Reply via email to