I used to have a named verb "idMat" in my own utilities library that was
defined this way:
idMat=: =@:i.

but testing this on large arguments led me to formulate this
idMat=: 3 : '(2$y)$(>:y){.1'  NB.* faster and scales better

or, the same thing tacitly:
idMat=: (2 $ ]) $ 1 {.~ >:


On Tue, Nov 20, 2012 at 2:29 PM, Don & Cathy Kelly <d...@shaw.ca> wrote:

> 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<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<http://www.jsoftware.com/forums.htm>
>>
>>
> ------------------------------**------------------------------**----------
> For information about J forums see 
> http://www.jsoftware.com/**forums.htm<http://www.jsoftware.com/forums.htm>
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to