In [ ]:
    
length=: %:@:(+/@:*:)"1
    
In [ ]:
    
length 3 4
    
In [ ]:
    
length 3 4 12
    
The function:
   ```X=: +/ . \*```
is the matrix product.
If m is a matrix, and v is a vector, the result of m X v may differ from v in both length and direction.
However, if m is a matrix whose row and column sums are of length 1, then the result of m X v has the same length as v The operation is called a rotation, and m is called a rotation matrix. For example:
In [ ]:
    
X=: +/ . *
    
In [ ]:
    
v=: 3 4
    
In [ ]:
    
m=: > 1 2;2 1
    
In [ ]:
    
m
    
In [ ]:
    
m X v
    
In [ ]:
    
length m X v
    
In [ ]:
    
length v
    
In [ ]:
    
c=: % %: 2        NB. Reciprocal of square root of 2
    
In [ ]:
    
m=: > (c, c);((-c),c)
    
In [ ]:
    
m
    
In [ ]:
    
length m          NB. Lengths of rows of m
    
In [ ]:
    
|: m              NB. Transpose of m
    
In [ ]:
    
length |: m       NB. Lengths of columns of m
    
In [ ]:
    
m X v
    
In [ ]:
    
length m X v
    
In [ ]:
    
load 'trig'
    
In [ ]:
    
r=: (cosd , -@:sind) ,. (sind , cosd)
    
In [ ]:
    
m=: r 45
    
In [ ]:
    
m
    
In [ ]:
    
m X v
    
In [ ]:
    
y=: (r 90) X v
    
In [ ]:
    
y
    
In [ ]:
    
y X v       NB. 90-degree rotation produces a perpendicular vector
    
In [ ]:
    
r 30
    
In [ ]:
    
rx30=: 1 0 0,0 0,.r 30
    
In [ ]:
    
rx30
    
In [ ]:
    
w=: 3 4 5
    
In [ ]:
    
rx30 X w
    
In [ ]:
    
length w
    
In [ ]:
    
length rx30 X w
    
In [ ]:
    
ry45=: 1 0 2 { 1 0 2 ({"1) 1 0 0,0 0,.r 45
    
In [ ]:
    
rz60=: 1 2 0 { 1 2 0 ({"1) 1 0 0,0 0,.r 60
    
In [ ]:
    
ry45
    
In [ ]:
    
ry45 X w
    
In [ ]:
    
rz60
    
In [ ]:
    
rz60 X w
    
In [ ]:
    
rall=: rx30 X ry45 X rz60
    
In [ ]:
    
rall
    
In [ ]:
    
length rall
    
In [ ]:
    
rall X w
    
In [ ]:
    
GR=: 4 : 0
res=: (i. =/ i.) 3       NB. Initialize res as identity matrix
p=: >0 1 2;1 0 2;1 2 0   NB. Permutations for axes
while. 0<# x do.
cp=. ('xyz'i.{:x){p                 NB. Current permutation
cr=. cp {"1 cp { 1 0 0,0 0,.r {: y  NB. Current rotation
res =. cr X res
x=. }: x
y=. }: y
end.
res
)
    
In [ ]:
    
'xyz' GR 30 45 60
    
In [ ]:
    
'yx' GR 45 60
    
In [ ]:
    
'y' GR 45
    
In [ ]:
    
'xyxyx' GR 1 2 3 4 5
    
In [ ]: