I wouldn’t wish pencil and paper matrix multiplication algebra on my worst enemy. Well, on second thought…… Anyway, Michael Kelley describes it as, “The trickiest thing you’ll need to do with matrices.” In Kelley’s Algebra, Chapter 9, pg 118-120, he shows the process of multiplying a 2 row 2 column matrix times a 2 row 3 column matrix. In Kelley’s Example 4, he shows how to solve the problem in 18 steps using a two finger approach. So, let’s do the same problem using J instead.
But first, before multiplying two matrices, the matrices must follow the row-column requirement: the number of columns in the first matrix must equal the number of rows in the second matrix. As shown below in the J format, the numbers that must be equal are highlighted in yellow in the left side arguments for the shape ($) command. The shape ($) command arguments on both sides must be in row, column order. If those two numbers aren’t equal, you can’t multiply the matrices. Then, the numbers in each matrix are entered in row column order.
With the row column requirement satisfied, you use matrix product A + / . * B to solve it:
You can check this answer against the answer in Kelley’s textbook, pg 120.
I had a problem in J when I first worked the problem. I had to go back to I-APL to figure out what was going wrong. Everything worked in I-APL with the equivalent of J’s matrix product (verb) command. I finally discovered that J requires that the arguments ( + / . *) have a space between each of them. Then, it works.
If you have a copy of Kelley’s Algebra available, you might want to go through the pencil and paper steps of matrix multiplication, p. 118-120, at least once to figure out what J’s matrix product is doing. But, I think once should be enough.
Matrix addition, subtraction, scalar multiplication, and determinants coming soon.