Lets get our hands dirty by doing some awesome math this time.
WHY MATRICES?
Matrices find applications in computer graphics, image processing, data storage, and, of course, AI.
Numerous CSS variables involve matrix manipulations:
- transform: rotate()
- transform: scale()
- transform: translate()
- matrix()
- transform: matrix()
- transform: matrix3d()
WebGL, in particular, is a vast playground where matrices come into play extensively.
In AI, about 99% of it involves statistics applied to matrices through machine learning techniques.
Consider a matrix as an image of a banana broken down into pixels. Through machine learning statistical methods, one can discern whether it’s a banana, its length, or if it’s a short or long banana.
In the .NET Compact Framework 3.5, an older rigid framework for embedded systems where image rotation was absent, I transformed images into matrices. Then, I applied mathematical operations to rotate them pixel by pixel, ultimately presenting them as images.
LET’S PROCEED
Adding matrices is relatively straightforward: we simply add corresponding cells in each matrix. However, multiplying them is a tad more intricate.
To multiply matrices, we follow a specific method where each cell in a parent row is multiplied by each cell in the corresponding parent column.
Now, why do we follow this seemingly complex method? In the realm of engineering, complexity often signifies something intriguing.
THE CORE QUESTION
Why do we multiply matrices in this manner? We easily sum same-position cells, but why involve parent rows and columns in multiplication?
The answer touches upon higher dimensions, space, and mathematical intricacies. Mathematicians may shy away from a direct explanation. Yet, as software engineers, we’ll undertake the challenge of explaining it in an “incorrect” but functional way.
Let’s simplify it significantly.
MILK CRATES, PLEASE
Matrices, much like Typescript is to Javascript, encompass vectors. Vectors represent space in the real world, serving as coordinates for an object in space.
In our analogy, matrices are akin to objects in space.
Consider adding two objects in space—say, two crates of milk. The result? Simply put, two crates of milk.
Now, ponder multiplying two crates of milk. It becomes quite a challenge to visualize, doesn’t it? This complexity mirrors why we employ the intricate method for matrix multiplication.
Here, we treat each component of the milk crate as a point in space. Each point represents a vector. As storing the vector and its calculations becomes impractical, we represent the result as the multiplication of parent columns by parent rows. Essentially, the intricate calculations involved are, in essence, a vector.
BOUNDS OF IMAGINATION…
I’ll venture further into the explanatory realm by providing visual representations for both addition and multiplication of matrices.
Visualize adding one box to another—an easy mental image.
Now, picture multiplying a box by itself. Don’t fret; I’ve visualized this for you. If it seems like a transparent 3D box, that’s precisely what it is!
Multiplying a 2D box with itself yields a box from the subsequent dimension—a 3D box. This conceptual joining of two boxes at the end results in a singular 3D box, illustrating why we multiply matrices in this peculiar manner. It’s a move away from mere aggregation of boxes, as in addition.
PUSHING THE BOUNDARIES
In matrix multiplication, we employ dot products between rows of the first matrix and columns of the second matrix.
This summation of multiplying columns and rows is what we refer to as the dot product.
My reference to milk crates and dimensions likely stems from my fascination with concepts like the fourth dimension. In formulas calculating the fourth dimension of an object, one invariably encounters the dot product in Euclidean three-dimensional space.
This, essentially, elucidates how we compute the next-dimensional whirl of an object. All that’s been discussed earlier serves as a study, seeking to answer the query: “Why do we multiply matrices in this peculiar way?”
THE SATISFYING CONCLUSION
…And here’s the ultimate response:
…It’s akin to multiplying real-world, 3-dimensional objects—much like multiplying one crate of milk with another.
Such calculation, anyway, it is and should be tricky, isnt it?
This is the reason we make our lifes hard on it.
✌️