Or,

   c=:(*=)&i.
   y=:5
   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

and since i. generates unique items it get around Roger's caveat of using 
monadic =

Cheers, bob

On 2012-11-20, at 5:14 AM, Linda Alvord wrote:

> Don,
> 
> Now that we have  =i.5  it could be in the dictionary under "identity
> matrix"
> 
> And, you might like this:
> 
>   c=: 13 :'(i.y)*=i.y'
>   c
> i. * [: = i.
> 
>   c 5
> 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
> 
> Linda
> 
> 
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Ric Sherlock
> Sent: Tuesday, November 20, 2012 4:40 AM
> To: [email protected]
> Subject: Re: [Jprogramming] Verb definition + inadvertent train formation.
> 
> I can't really claim any credit here. I was just repeating the code from
> earlier in the thread. I just left out the atop conjunction ( @ ) that is
> used to enable the sentence to be assigned to a name as a
> verb:
>   =@i.@# 33 4 4 33 2
> 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
>   = i. # 33 4 4 33 2
> 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
> 
> On Tue, Nov 20, 2012 at 6:27 PM, Bo Jacoby <[email protected]> wrote:
>> I have never written a J program that couldn't be improved . Well done,
> Ric!
>> 
>> - Bo
>> 
>> 
>> 
>> 
>>> ________________________________
>>> Fra: Ric Sherlock <[email protected]>
>>> Til: [email protected]
>>> Sendt: 6:04 tirsdag den 20. november 2012
>>> Emne: Re: [Jprogramming] Verb definition + inadvertent train formation.
>>> 
>>> Yes and I think I prefer that formulation however monadic = works too:
>>>  = 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
>>> 
>>> On Tue, Nov 20, 2012 at 6:01 PM, Bo Jacoby <[email protected]> wrote:
>>>> 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
>>> ----------------------------------------------------------------------
>>> 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
> 
> ----------------------------------------------------------------------
> 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