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
On 18/11/2012 6:07 PM, km wrote:
You can get help from Phrases for extracting diagonal elements. See
the bottom half of this page:
http://www.jsoftware.com/docs/help701/phrases/special_matrices.htm
Kip Murray
Sent from my iPad
On Nov 18, 2012, at 7:51 PM, Don & Cathy Kelly <d...@shaw.ca> wrote:
This also helped me where I wanted to extract the diagonal elements
of an array!
I was trying for a neater way to do it but as in the end, I have to
do it several times, it appears that it is easier to establish a
unit matrix and then use this each time I want to deal with a
matrix of the same size
rather than using (* =@i.@#) y and repeating for different y or
using the cap as you suggest, I can simply define a unit matrix U
and then us U*y as needed.
Still very hit and miss on the multiple ways to skin a cat in J
Don Kelly
On 15/11/2012 9:55 PM, bob therriault wrote:
Hey Vijay,
Nothing wrong with a novice question, especially when it is so
clearly phrased.
Take a look at these examples and see if this gives you some ideas.
fact1=: */@:>:@:i.
fact1 5
120
fact2=: [:*/>:@:i.
fact2 5
120
fact3=: [:*/[:>:i.
fact3 5
120
You want to have the verbs act sequentially on the argument and
your original definition is a fork which has the outside verbs act
on the argument and then send the results to the left and the right
of the centre verb.
(v1 v2 v3) y is actually ((v1 y) v2 (v3 y)). In this case (*/ >:
i.) 5 becomes ((*/ 5) >: (i. 5)) and then (5 >: 0 1 2 3 4) which
becomes 1 1 1 1 1
A good reference link would be
http://www.jsoftware.com/jwiki/Guides/Language%20FAQ#Guides.2FLanguage_FAQ.2FSentence_Train.Why_.2B-.2F_.2A:_a_works.2C_but_when_I_say_foo_.3D:_.2B-.2F_.2A:.2C_foo_a_doesn.27t_work.3F
Hope this helps. There is a lot to this language, even when you
have been playing with it for a while, so keep at it.
Cheers, bob
On 2012-11-15, at 9:20 PM, Vijay Lulla wrote:
Please forgive me for asking a novice question.
I tried
*/>:i.5 NB. results in 120
But I define
fact=: */>:i.
fact 5 NB. results in 1 1 1 1 1
I remember reading about this somewhere but I cannot seem to find the
relevant pages now. Any pointers as to where I could find these
documents
or a brief explanation (which can be easily remembered) will be very
helpful and is highly appreciated.
Thanks,
Vijay Lulla.
----------------------------------------------------------------------
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