The unit matrix is
   =/~i.5
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1

- Bo





>________________________________
> Fra: Don & Cathy Kelly <[email protected]>
>Til: [email protected] 
>Sendt: 0:47 tirsdag den 20. november 2012
>Emne: Re: [Jprogramming] Verb definition + inadvertent train formation.
> 
>No - I should have made it clear that the actual y is a list of n 
>numbers and I need to add this list to the diagonal of a matrix.
>Since this will (of necessity) be within a loop and each time both the 
>list and matrix will be modified (except for size),
>I have come to the conclusion that I should make a single unit matrix 
>outside the iteration and use this each time.
>   ] u=:=@i.@#i.5
>
>1 0 0 0 0
>0 1 0 0 0
>0 0 1 0 0
>0 0 0 1 0
>0 0 0 0 1
>
>y=: 2 3 5 4 10
>
>    ]u *y
>2 0 0 0  0
>0 3 0 0  0
>0 0 5 0  0
>0 0 0 4  0
>0 0 0 0 10
>repeating with different y values as needed.
>
>The algorithm for u is taken from the "phrases" section of the 
>vocabulary-maybe you have a simpler one?-
>Thanks
>
>Don
>
>
>On 18/11/2012 10:33 PM, bob therriault wrote:
>> Hi Don,
>>
>> Are you looking for
>>
>> y=:5
>>     c=:(*=)&i.
>>     c y
>> 0 0 0 0 0
>> 0 1 0 0 0
>> 0 0 2 0 0
>> 0 0 0 3 0
>> 0 0 0 0 4
>
>> Cheers, bob
>>
>> On 2012-11-18, at 7:13 PM, Don & Cathy Kelly wrote:
>>
>>> OOPs' I meant y=:i.5 5
>>>
>>> Don
>>> On 18/11/2012 7:04 PM, Don & Cathy Kelly wrote:
>>>> That gives the diagonal nicely  but the problem that I didn't express 
>>>> clearly is that I want a matrix as follows
>>>>    y=:i.5
>>>>
>>>>    ]result =: (* =@i.@#) y
>>>> 0 0 0 0 0
>>>> 0 1 0 0 0
>>>> 0 0 2 0 0
>>>> 0 0 0 3 0
>>>> 0 0 0 0 4
>>>> which II can get by
>>>> c=:* =@i.@#
>>>>    c y
>>>> 0 0 0 0 0
>>>> 0 1 0 0 0
>>>> 0 0 2 0 0
>>>> 0 0 0 3 0
>>>> 0 0 0 0 4
>>>>
>>>> For my purposes I can use a base nth order unit matrix by the phrase as 
>>>> given in phrases as  m=:=@i.@# y
>>>> and then deal with m* y1 , m* y2 etc which suits my purpose which is to 
>>>> form a specific Jacobean used for power system load flows.
>>>> I have handled this problem in APL  and am trying to replicate the coding 
>>>> more directly in J-mainly as an exploration of J for my own satisfaction.
>>>>
>>>> Thank you
>>>>
>>>> Don Kelly
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>----------------------------------------------------------------------
>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