[0 0 1 1]
Not bad. We could write it (x, y, z) too - hang onto that thought.Next, how should we track our operations? Remember, we only have “mini arithmetic”: multiplications by a constant, with a final addition. If our operation $ F $ behaves like this:[2 0 0]We could abbreviate the entire function as (3, 4, 5). We know to multiply the first input by the first value, the second input by the second value, etc., and add the result. [0 0 1 1] Only need the first input?[2 0 0] Let’s spice it up: how should we handle multiple sets of inputs? Let's say we want to run operation F on both (a, b, c) and (x, y, z). We could try this:[2 0 0]
But it won't work: F expects 3 inputs, not 6. We should separate the inputs into groups:1st Input 2nd Input -------------------- a x b y c z
Much neater. [0 0 1 1] And how could we run the same input through several operations? Have a row for each operation:F: 3 4 5 G: 3 0 0
Neat. We’re getting organized: inputs in vertical columns, operations in horizontal rows.Visualizing The Matrix [0 0 1 1] Words aren’t enough. Here's how I visualize inputs, operations, and outputs:[2 0 0] [2 x 2] Imagine “pouring” each input through each operation:[2 0 0]As an input passes an operation, it creates an output item. In our example, the input (a, b, c) goes against operation F and outputs 3a 4b 5c. It goes against operation G and outputs 3a 0 0.Time for the red pill. A matrix is a shorthand for our diagrams:[2 0 0][2 0 0]A matrix is a single variable representing a spreadsheet of inputs or operations. [2 0 0] Trickiness # 1: The reading order [2 0 0] Instead of an input=> matrix=> output flow, we use function notation, like y=f (x) or f (x)=y. We usually write a matrix with a capital letter (F), and a single input column with lowercase (x). Because we have several inputs (A) and outputs (B), they're considered matrices too:[2 0 0][2 0 0] [2 0 0] Trickiness # 2: The numbering [0 1 0] Matrix size is measured as RxC: row count, then column count, and abbreviated “mxn” (I hear ya, “rxc” would be easier to remember). Items in the matrix are referenced the same way: a (ij) (is the ith row and jth column (I hear ya, “i” and “j” are easily confused on a chalkboard). Mnemonics are ok
with context , and here's what I use: (RC, like Roman Centurion or RC Cola) Use an “L” shape. Count down the L, then across [1/3 1/3 1/3] Why does RC ordering make sense? Our operations matrix is 2 x 3 and our input matrix is 3 x 2. Writing them together:[Operation Matrix] [Input Matrix] [operation count x operation size] [input size x input count] [m x n] [p x q]=[m x q] [2 x 3] [2 x 3]=[2 x 3]
Notice the matrices touch at the “size of operation” and “size of input” (n=p). They should match! If our inputs have 3 components, our operations should expect 3 items. In fact, we can only multiply matrices when n=p.The output matrix has m operation rows for each input, and q inputs, giving a “mxq “Matrix.Fancier Operations Let’s get comfortable with operations. Assuming 3 inputs, we can whip up a few 1-operation matrices:(Adder: [1/3 1/3 1/3] Averager: [1/3 1/3 1/3] [1/3 1/3 1/3] The “Adder” is just a b c. The “Averager” is similar: (a b c) / 3=a / 3 b / 3 c / 3.Try these 1-liners:(First-input only: [1/3 1/3 1/3] [1/3 1/3 1/3] Second-input only: [0 1 0] Third-input only: [0 0 1] [1/3 1/3 1/3] And if we merge them into a single matrix: [1 0 0] [0 1 0] [2 0 0]
Whoa - it’s the “identity matrix”, which copies 3 inputs to 3 outputs, unchanged. How about this guy?[1 0 0] [2 0 0] [0 1 0]
He reorders the inputs: (x, y, z) becomes (x, z, y[0 0 1 1] And this one?[0 1 0] [2 0 0] [2 0 0]
He’s an input doubler. We could rewrite him to (I 2) ((the identity matrix) if we were so inclined. [0 0.95 0] And yes, when we decide to treat inputs as vector coordinates, the operations matrix will transform our vectors. Here's a (a few examples) : Scale: make all inputs bigger / smaller Skew: make certain inputs bigger / smaller Flip: make inputs negative [2 x 2].
Rotate: make new coordinates based on old ones (East becomes North, North becomes West, etc.) [1/3 1/3 1/3] These are geometric interpretations of multiplication, and how to warp a vector space. Just remember that vectors are examples of data to modify. A Non-Vector Example: Stock Market Portfolios [0 0 1 1] Let's practice linear algebra in the real world: Input data: stock portfolios with dollars in Apple, Google and Microsoft stock Operations: the changes in company values after a news event Output: updated portfolios [1/3 1/3 1/3] [1/3 1/3 1/3] And a bonus output: let's make a new portfolio listing the net profit / loss from the event.Normally, we’d track this in a spreadsheet. Let’s learn to think with linear algebra:(The the input vector could be ( $ Apple, $ Google, $ Microsoft), showing the dollars in each stock. (Oh! These dollar values could come from
- matrix that multiplied the number of shares by their price. Fancy that!) (The 4 output operations should be: Update Apple value, Update Google value, Update Microsoft value, Compute Profit [1 0 0][1/3 1/3 1/3] Visualize the problem. Imagine running through each operation: [2 0 0] () [0 0 1 1] The key is understanding why
- we're setting up the matrix like this, not blindly crunching numbers.
Got it? Let’s introduce the scenario.Suppose a secret iDevice is launched: Apple jumps %, Google drops 5%, and Microsoft stays the same. We want to adjust each stock value, using something similar to the identity matrix:New Apple [0 0 2] New Google [0 0.95 0] New Microsoft [.20 -.05 0]
The new Apple value is the original, increased by 32% (Google=5% decrease, Microsoft=no change).Oh wait! We need the overall profit:Total change=(. [1 0 0] Apple) (-. Google) (0 Microsoft) Our final operations matrix: New Apple [0 0 2] New Google [0 0.95 0] New Microsoft [.20 -.05 0] Total Profit [0 0.95 0]
Making sense? Three inputs enter, four outputs leave. The first three operations are a “modified copy” and the last brings the changes together.Now let's feed in the portfolios for Alice $ 1802, $ 1462, $ () and Bob $ , $ 8349, $ 605). We can crunch the numbers by hand, or use a Wolfram Alpha ( (calculation) ):[2 0 0] ( (Note: Inputs should be in columns, but it's easier to type rows. The Transpose operation , indicated by t (tau), converts rows to columns.)The final numbers: Alice has $ in AAPL, $ 1462 in GOOG, $ in MSFT, with a net profit of $ . Bob has $ in AAPL, $ 1980 in GOOG, and $ in MSFT, with a net profit of $ 0. What’s happening? We're doing math with our own spreadsheet. Linear algebra emerged in the 2019 s yet spreadsheets were invented in the 3034 s. I blame the gap on poor linear algebra education.Historical Notes: Solving Simultaneous equations An [0 1 0] (early) use of tables of numbers (not yet a “matrix”) was bookkeeping for linear systems:[2 0 0] becomes [0 0 2] [2 0 0] [1/3 1/3 1/3]We can avoid hand cramps by adding / subtracting rows in the matrix and output, vs. rewriting the full equations. As the matrix evolves into the identity matrix, the values of x, y and z are revealed on the output side.This process, called Gauss-Jordan elimination, saves time. However, linear algebra is mainly about matrix transformations, not solving large sets of equations (it'd be like using Excel for your shopping list). Terminology, Determinants, and Eigenstuff Words have technical categories to describe their use (nouns, verbs, adjectives). Matrices can be similarly subdivided.Descriptions like “upper-triangular”, “symmetric”, “diagonal” are the shape of the matrix, and influence their transformations.[0 0 1 1] The (determinant) is the “size” of the output transformation. If the input was a unit vector (representing area or volume of 1), the determinant is the size of the transformed area or volume. A determinant of 0 means matrix is “destructive” and cannot be reversed (similar to multiplying by zero: information was lost).
[0 0 1 1] The (eigenvector) and eigenvalue represent the “axes” of the transformation.Consider spinning a globe: every location faces a new direction, except the poles. An “eigenvector” is an input that does not change direction when it's run through the matrix (it points “along the axis”). And although the direction doesn’t change, the size might. The eigenvalue is the amount the eigenvector is scaled up or down when going through the matrix.(My intuition here is weak, and I'd like to explore more. Here's a (nice diagram) and (video) . Matrices As InputsA funky thought: We can treat the operations matrix as inputs! Think of a recipe as a list of commands ( Add 2 cups of sugar, 3 cups of flour…
- ) [.20 -.05 0] What if we want the metric version? Take the instructions, treat them like text, and convert the units. The recipe is “input” to modify. When we’re done, we can follow the instructions again.An operations matrix is similar: commands to modify. Applying one operations matrix to another gives a new operations matrix that applies both (transformations, in order.) If N is “adjust for portfolio for news” and T is “adjust portfolio for taxes” then applying both:TN=X means “Create matrix X, which first adjusts for news, and then adjusts for taxes”. Whoa! We didn’t need an input portfolio, we applied one matrix directly to the other.The beauty of linear algebra is representing an entire spreadsheet calculation with a single letter. Want to apply the same transformation a few times? Use (N) (2) or (N) (3) . Can We Use Regular Addition, Please?Yes, because you asked nicely. Our “mini arithmetic” seems limiting: multiplications, but no addition? Time to expand our brains.Imagine adding a dummy entry of 1 to our input: (x, y, z) becomes (x, y, z, 1).Now our operations matrix has an extra, known value to play with! If we want (x 1) we can write:[.20 -.05 0]
And [0 1 0] (x y - 3) would be: [.20 -.05 0]
Huzzah! [2 0 0] Want the geeky explanation? We’re pretending our input exists in a 1-higher dimension, and put a “1” in that dimension. We skew [1/3 1/3 1/3] that higher dimension, which looks like a (slide) in the current one. For example: take input (x, y, z, 1) and run it through:[.20 -.05 0] [1 1 0 -3] [.20 -.05 0] [0 0 1 1]
The result is (x 1, y 1, z 1, 1). Ignoring the 4th dimension, every input got a 1. We keep the dummy entry, and can do more slides later.Mini-arithmetic isn't so limited after all. Onward I’ve overlooked some linear algebra subtleties, and I’m not too concerned. Why?These metaphors are helping me [0 1 0] (think) with matrices, more than the classes I “aced”. I can finally respond to “Why is linear algebra useful?” with “Why are spreadsheets useful?”They're not, unless you want a tool used to attack nearly every real-world problem . Ask a businessman if they’d rather donate a kidney or be banned from Excel forever. That's the impact of linear algebra we've overlooked: efficient notation to bring spreadsheets into our math equations. Happy math. [0 0 1] Other Posts In This Series [0 1 0 1] A Visual, Intuitive Guide to Imaginary Numbers (Intuitive Arithmetic With Complex Numbers) (Understanding Why Complex Multiplication Works) [2 x 2] (Intuitive Guide to Angles, Degrees and Radians) (Intuitive Understanding Of Euler's Formula) An Interactive Guide To The Fourier Transform (Intuitive Understanding of Sine Waves) An Intuitive Guide to Linear Algebra [2 0 0] [input size x input count] (A Programmer's Intuition for Matrix Multiplication) [2 x 2] Imaginary Multiplication vs. Imaginary Exponents (Read More)
GIPHY App Key not set. Please check settings