Jump to content

Matrix multiplication: Difference between revisions

m
→‎{{header|J}}: lang tags, use mp instead of x to prevent confusion with x used as argument later
m (alphabetize TI-*)
m (→‎{{header|J}}: lang tags, use mp instead of x to prevent confusion with x used as argument later)
Line 609:
 
=={{header|J}}==
Matrix multiply in J is just <ttcode>+/ .*</ttcode>. For example:
<lang j>
 
xmp =: +/ .* NB. Matrix product
A =: ^/~>:i. 4 NB. Same A as in other examples (1 1 1 1, 2 4 8 16, 3 9 27 81,:4 16 64 256)
B =: %.A NB. Matrix inverse of A
'6.2' 8!:2 A x B
1.00 0.00 0.00 0.00
0.00 1.00 0.00 0.00
0.00 0.00 1.00 0.00
0.00 0.00 0.00 1.00
A =: ^/~>:i. 4 NB. Same A as in other examples (1 1 1 1, 2 4 8 16, 3 9 27 81,:4 16 64 256)
B =: %.A NB. Matrix inverse of A
'6.2' 8!:2 A xmp B
1.00 0.00 0.00 0.00
0.00 1.00 0.00 0.00
0.00 0.00 1.00 0.00
0.00 0.00 0.00 1.00
</lang>
The notation is for a generalized inner product so that
<lang j>
x ~:/ .*. y NB. boolean inner product (<tt>~: </tt>is "not equal" (exclusive or) and<tt> *. </tt>is "and")
x *.~:/ .= *. y NB. whichboolean rowsinner ofproduct x(<tt>~: are</tt>is the"not sameequal" as(exclusive vectoror) y?and<tt> *. </tt>is "and")
x + *./ .= y NB. numberwhich rows of placesx whereare eachthe row of xsame equalsas vector y?
x + / .= y NB. number of places where each row of x equals vector y
</lang>
etc.
 
892

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.