Matrices
A matrix looks like a table of numbers, but it is the most compact way to write down an entire circuit, a rotation or the chaining of two amplifier stages.
01A table that also does arithmetic
A matrix is a rectangular array of numbers arranged in rows and columns. So far it is just a table. What turns it into a tool is that operations are defined on that array —addition, multiplication, inverse— and they stand for concrete things: solving a circuit, rotating a vector, chaining two stages of an amplifier.
Row first, then column. All the notation that follows —the product, the transpose, the determinant— depends on respecting it. A subscript error does not give a strange result: it gives a different result that looks reasonable, which is worse.
Two matrices are equal if they have the same order and agree element by element. There is no possible equality between a 2 × 3 matrix and a 3 × 2 matrix.
02Matrices with a name of their own
| Name | What it looks like | Where it shows up |
|---|---|---|
| Row and column | \( 1 \times n \) and \( m \times 1 \) | A vector written as a matrix. In electronics, the vector of mesh currents |
| Square | \( m = n \) | It is the only kind that can have an inverse, a determinant and eigenvalues |
| Diagonal | \( a_{ij} = 0 \) if \( i \ne j \) | Multiplying by it scales each component separately |
| Identity I | Diagonal with ones | The “1” of matrix multiplication: \( A \cdot I = I \cdot A = A \) |
| Triangular | Zeros above or below the diagonal | This is what Gaussian elimination leads to; its determinant is the product of the diagonal |
| Transpose AT | Rows and columns are swapped | \( (A \cdot B)^T = B^T \cdot A^T \), with the order reversed |
| Symmetric | \( A = A^T \) | The impedance matrix of a passive network, by the reciprocity theorem |
| Zero | All zeros | The identity element of addition. Careful: \( A \cdot B = 0 \) does not force A or B to be zero |
03Addition and scalar multiplication
The two easy operations are done element by element, and they require the matrices to have the same order:
With those properties, the set of matrices of a fixed order is a vector space: the structure that is studied in detail later in this same course.
04The product: rows by columns
Here intuition breaks down. The product is not element by element. The element cij of the product is the dot product of row i of A with column j of B:
Tap a cell of the result and the computation that produced it appears:
Change the numbers and the dimensions. Tapping a cell of the result shows the row-by-column computation.
A
B
A · B
In general A·B ≠ B·A, and often B·A cannot even be computed. Try the button “Compute B · A” in the lab. Associativity, A(BC) = (AB)C, and distributivity, A(B + C) = AB + AC, do hold. What does not hold is cancellation: AB = AC does not imply B = C.
05The inverse matrix
Dividing matrices does not exist. What exists is the inverse: the matrix that undoes what A does.
For 2 × 2 there is a direct formula: swap the entries on the main diagonal, change the sign of the other two and divide by the determinant.
For larger orders you use Gauss-Jordan elimination: you write [A | I] and perform row operations until you reach [I | A−1]. The method appears in full in the topic on systems of linear equations.
For A = [[2, 1], [5, 3]]: det = 2·3 − 1·5 = 1, so A−1 = [[3, −1], [−5, 2]].
Check: A·A−1 = [[2·3 + 1·(−5), 2·(−1) + 1·2], [5·3 + 3·(−5), 5·(−1) + 3·2]] = [[1, 0], [0, 1]]. ✔
Two properties that are used all the time: (A·B)−1 = B−1·A−1 —just like taking off your clothes: the last thing you put on comes off first— and (A−1)−1 = A.
06Rank: how much information there really is
The rank of a matrix is the number of linearly independent rows, that is, how many rows contribute new information. It is computed by bringing the matrix to row echelon form with elementary operations (swapping two rows, multiplying a row by a nonzero scalar, adding to a row a multiple of another) and counting the rows that did not end up zero.
In [[1, 2, 3], [2, 4, 6], [1, 0, 1]], the second row is twice the first. Subtracting 2 times the first leaves it zero: the rank is 2, not 3. That means, for example, that the associated system of equations has one equation too many, which adds no condition.
The rank decides almost everything that follows: whether a system has a solution and how many, whether a matrix is invertible (an n × n matrix is invertible only if its rank is n) and what the dimension of the image of a linear transformation is.
07What this is good for in electronics
An entire circuit in one equation
Nodal analysis of a network of n nodes is written as Y · V = I, where Y is the admittance matrix, V the vector of node voltages and I the vector of injected currents. The matrix is built almost without thinking: on the diagonal, the sum of the admittances meeting at each node; off the diagonal, the admittance between the two nodes, with its sign changed. Solving the circuit is solving the system.
Cascaded stages: the product is the connection
A two-port network —an amplifier stage, a filter, a section of transmission line— is described by its matrix of ABCD parameters, which relates the input to the output. And here is the elegant part: connecting two stages in cascade means multiplying their matrices, in the order in which the signal passes through them.
That is why it matters that the product is not commutative: swapping two stages of a circuit gives another circuit, with a different response. The algebra is not an analogy, it is exactly what happens. The transmission lines described this way appear in the Smith chart.
There is more: the rotation matrix turns a phasor by an angle φ, transition matrices describe state machines and the truth tables of a digital system are, in the end, matrices of zeros and ones.
08In the lab
For a three-node network with five resistors of your choice, write the admittance matrix, verify that it is symmetric and that the sum of each row gives the admittance to the reference node. Solve V = Y−1·I with a calculator or with Octave, and check it with an LTspice simulation.
With any two 2 × 2 matrices, compute A·B and B·A by hand and verify that they differ. Then look for two matrices that do commute (for example, two diagonal ones) and explain why.
In GNU Octave or Python with NumPy: create matrices, multiply them, invert them and time how long it takes to
invert a 500 × 500 one. Compare A*B (matrix product) with A.*B
(element by element) so you never confuse them again.
09Common mistakes
- Multiplying element by element. That is a different operation (the Hadamard product), and it is no use for solving systems.
- Not checking the dimensions before multiplying: if the inner ones do not match, the product does not exist.
- Reversing the order in (A·B)T or (A·B)−1.
- Cancelling as with numbers: A·B = A·C does not imply B = C, unless A is invertible.
- Trying to invert a non-square matrix or one with a zero determinant.
- Confusing the zero matrix with the identity as the identity element: the zero matrix is the one for addition, the identity for multiplication.
10Self-assessment
If A is 4 × 3 and B is 3 × 5, what is the order of A·B? And of B·A?
A·B is 4 × 5. B·A does not exist: the inner dimensions (5 and 4) do not match.
Compute [[1, 2], [0, 3]] · [[4, 0], [1, 5]].
[[1·4 + 2·1, 1·0 + 2·5], [0·4 + 3·1, 0·0 + 3·5]] = [[6, 10], [3, 15]].
When does a square matrix of order n have an inverse?
When its determinant is nonzero, which is the same as saying that its rank is n or that its rows are linearly independent.
The inverse of [[3, 1], [2, 1]].
det = 3 − 2 = 1, so the inverse is [[1, −1], [−2, 3]].
What is the rank of [[1, 1], [2, 2]]?
1: the second row is twice the first and vanishes when you reduce to echelon form. Therefore the matrix has no inverse, and its determinant is zero.
Why is the admittance matrix of a passive network symmetric?
Because the admittance between nodes i and j is the same seen from either of the two: this is the reciprocity theorem. It stops being symmetric if there are active elements, such as controlled sources.
11Further reading
- Stanley I. Grossman. Álgebra lineal. 6th ed., McGraw-Hill, 2008 (in Spanish). The most widely used text in Argentine engineering schools: matrices and determinants with many worked exercises.
- Gilbert Strang. Linear Algebra and Its Applications. 4th ed. (Spanish edition, “Álgebra lineal y sus aplicaciones”), Cengage Learning, 2007. It treats matrices as transformations and as operations on columns. His lectures are free on MIT OCW.
- David C. Lay. Linear Algebra and Its Applications. 5th ed. (Spanish edition, “Álgebra lineal y sus aplicaciones”), Pearson, 2016. Very clear on rank, linear independence and applications to electrical networks.
- Frank Ayres. Schaum’s Outline of Matrices. (Spanish edition, “Matrices”, Schaum series), McGraw-Hill. If what you need is practice: hundreds of worked exercises, short and to the point.