I thought of this a few minutes before coming on line and tried it- it
is back to u=:=@i.@#
The # has to be there.
No problem as I only have to do it once.
Thanks
Don
On 19/11/2012 9:27 PM, Roger Hui wrote:
Use the phrases =y and =/~y with care. For example, try it when y has
duplicate elements:
y=: 3 1 4 1 5 9
=y
1 0 0 0 0 0
0 1 0 1 0 0
0 0 1 0 0 0
0 0 0 0 1 0
0 0 0 0 0 1
=/~y
1 0 0 0 0 0
0 1 0 1 0 0
0 0 1 0 0 0
0 1 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
On Mon, Nov 19, 2012 at 9:22 PM, Don & Cathy Kelly <d...@shaw.ca> wrote:
That should be in the phrases rather than what I used!
Ric's definition also works but not with a 5 element list
y=:2 3 6 8 9
= y
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
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
Thank you both - so many ways to skin a cat!
Don
On 19/11/2012 9:01 PM, Bo Jacoby 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 <d...@shaw.ca>
Til: programm...@jsoftware.com
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 <http://www.jsoftware.com/forums.htm>
------------------------------**------------------------------**
----------
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>
------------------------------**------------------------------**----------
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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm