Newsgroups: comp.lang.apl
Path: watmath!ljdickey
From: ljdickey@watmath.waterloo.edu (L. J. Dickey)
Subject: Re: Simple J questions
Message-ID: <1991Sep9.194216.28439@watmath.waterloo.edu>
Organization: University of Waterloo
References: <1991Sep1.225152.22316@csus.edu>
Date: Mon, 9 Sep 1991 19:42:16 GMT
Lines: 106

In article <1991Sep1.225152.22316@csus.edu> vpcsc4@sfsuvax1.sfsu.edu
	(Emmett James McLean) writes:
[edited. LJD ]
>These questions are probably answered in the book "Programming in J",
>but I understand that it may be a while before I get my copy since
>there is currently a mail strike in Canada.
>
>If I type the following J command
>	a=. 2 2 $ 1+i.4
>And,
>    b =. 0.7  0.9  0.2 0.25
>How do I get:
>
>1: (Multiply the 2nd column by 2)
>    1  4
>    3  8
>
>2: (Multiply the 2nd row by 2)
>    1  4 
>    6  8
>
>3: [catenate two matrices]
>    1  2  1  2
>    3  4  3  4
>
>4: (Change element 2 to 16)
>    1 16
>    3  4 
>
>5: (Add across the columns)
>    3  7  
>
>6: (Use the array of a to index into b)
>    0.7  0.9
>    0.2  0.25
>
>Similiarly, if :
>    c=. 2 2 2 $1+i. 8
>How do I get ?:
>
>7: (Multiply the top item by 2)
>      2  4 
>      6  8
>
>      5  6
>      7  8
>
>8: (Multiply the right column by 2 in both items)
>      1  4
>      3  8
>
>      5  12
>      7  16 
>
>9: (Add across the columns) 
>      3 7 11 15

Well, I shall venture out again.  Here are some answers that
work for me.

1: (Multiply the 2nd column by 2)
   a * 1 2
   
2: (Multiply the 2nd row by 2)
   a * "(1) 1 2
   a * "1 (1 2)
   
3: catenate two matrices
   a ,"1 a
   
4: [put a 16 in location 0 1 of a ]
   i =. < 0 1
   16 i } a

   16 (<0 1) } a
   
5: (Add across the columns) 3 7
   +/ "1 a
   
6: (Use the array of a to index into b)
   ($a)$(,a-1){b
   
Similiarly, if:
   c=. 2 2 2 $1+i. 8
   
7: (Multiply the top item by 2)
   c * "(1 0) 2 2 $ 2 1 1 1
Here are other examples that shows which indices are important:
   d =. i. 2 3 4
   d * "(1 0) 2 3 $ 2 1 1 1 1 1
   d * "(1 0) 2 3 $ 2 (0) }, 2 3 $ 1
   d * "(1 0) 2 (0 0)}2 3 $ 1
   
8: (Multiply the right column by 2 in both items)
   c * "1 (1 2)
or
   c * "(1) 1 2
   
9: (Add across the columns) 3 7 11 15
   ,+/"1 c

-- 
Prof Leroy J. Dickey, Faculty of Mathematics, U of Waterloo, Canada  N2L 3G1
Internet:      ljdickey@watmath.UWaterloo.ca
UUCP:          ljdickey@watmath.UUCP             ...!uunet!watmath!ljdickey
Obsolescent?:  ljdickey@watmath.waterloo.edu     BITNET/EARN: ljdickey@watdcs
