Use symbolic linear algebraLesson 31 of 48 · 8 min
A matrix acts on a vector
Calculate a matrix-vector product and interpret its rows.
Maths refresher: Rows times columns
Each output entry is a dot product: multiply corresponding entries and add them.
The first row gives . The second gives .
A matrix is a rectangular arrangement of entries. Multiplying a matrix by a column vector forms one output per row by summing products. This represents a linear transformation when the entries are fixed.
SymPy Matrix uses * for matrix multiplication, while NumPy array * multiplies elements in matching positions. Dimensions must agree: the matrix’s column count matches the vector’s row count. Keep the coordinate order attached to both input and output vectors.
The example shears a two-dimensional vector and then compares two orders of matrix transformations. In general and differ. An exact symbolic calculation can reveal that order dependence without rounding or a plot.
Will swapping two matrix transformations always leave the same result?
Write a prediction (optional)
Exact symbolic investigation
Select Run Python with the code unchanged.
Your saved draft is open. To use the published code, select Restore example in Tools. Use Recover draft to bring back your code.
Tools
About Python
Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗
Ctrl+Enter or ⌘+Enter runs Python.
Execution error
Technical error details
Your result
Python text output
Compare with the worked example
Executed from the published Python during the site build. Your own run appears above. Build environment ↗
Worked text output
A: Matrix([[1, 2], [0, 1]]) Input vector: Matrix([[3], [4]]) A acting on v: Matrix([[11], [4]]) A then B: Matrix([[22], [23]]) B then A: Matrix([[36], [15]])
Read the starter result
Read A acting on v and compare A then B with B then A. In a product applied to a vector, the transformation nearest the vector acts first.
Edit and compare
Replace v = sp.Matrix([3,4]) with v = sp.Matrix([1,0]) and select Run Python. Then use v = sp.Matrix([0,1]) and select Run Python again. Match each A acting on v vector to a column of A.
Scope. A matrix model needs meaningful coordinates and units; multiplication alone does not establish a real transformation’s validity.
Try a fresh case
For a 2×3 matrix multiplied by a column vector, what input size is required?
Need a hint?
Hint 1
Match the inner dimensions.
Hint 2
The output size follows the number of matrix rows.