Manipulating matrices in Julia
2026-01-23
juliauphttps://www.cs.cornell.edu/~bindel/nmds/
For noodling around, notebook environments are great
For presentation, I use Quarto
After installing Pluto:
Start with
Representation of
\[A \in \mathbb{R}^{m \times n}\]
\[A \in \mathbb{R}^{m \times n}\]
\[A = \begin{bmatrix} a_{1,:} \\ \vdots \\ a_{m,:} \end{bmatrix}\]
\[A = \begin{bmatrix} a_{:,1} & \ldots & a_{:,n} \end{bmatrix}\]
Matrix \(\times\) vector \(=\) linear combination of matrix columns.
Inner product \(=\) sum of products of corresponding elements.
Consider \(u, v, w \in \mathbb{R}^n\) where \(n = 10^6\), and let \(y = Aw\) for \(A = uv^T\)
Matrix \(\times\) diagonal \(=\) scaling of the matrix columns.
Diagonal \(\times\) matrix \(=\) scaling of the matrix rows.
Never form an explicit diagonal matrix.
Never form an explicit rank one matrix.
Matrix \(\times\) matrix \(=\) collection of matrix-vector products.
Matrix \(\times\) matrix \(=\) collection of dot products.
Matrix \(\times\) matrix \(=\) sum of rank one matrices.
Matrix \(\times\) matrix \(\implies\) linearly combine rows from the second matrix.
Matrix \(\times\) matrix \(\implies\) linearly combine columns from the first matrix.
This is really the same as saying
\[A \begin{bmatrix} b_1 & \ldots & b_n \end{bmatrix} = \begin{bmatrix} Ab_1 & \ldots & Ab_n \end{bmatrix}\]
\[M = \begin{bmatrix} A & b \\ c^T & d \end{bmatrix} = \begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \\ c_1 & c_2 & d \end{bmatrix}\]
For \(A \in \mathbb{R}^{m \times n}\)
Why is \(A\) sparse interesting?
Will discuss these points more later on
A dense matrix can still have compact storage / fast multiply!
Examples: