Matrix multiplication: Difference between revisions

Content added Content deleted
m (alphabetize TI-*)
m (→‎{{header|J}}: lang tags, use mp instead of x to prevent confusion with x used as argument later)
Line 609: Line 609:


=={{header|J}}==
=={{header|J}}==
Matrix multiply in J is just <tt>+/ .*</tt>. For example:
Matrix multiply in J is just <code>+/ .*</code>. For example:
<lang j>

x =: +/ .*
mp =: +/ .* 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 mp 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
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. which rows of x are the same as vector y?
x ~:/ .*. y NB. boolean inner product (<tt>~: </tt>is "not equal" (exclusive or) and<tt> *. </tt>is "and")
x + / .= y NB. number of places where each row of x equals vector y
x *./ .= y NB. which rows of x are the same as vector y?
x + / .= y NB. number of places where each row of x equals vector y
</lang>
etc.
etc.