Sign in

Libre University uses your GitHub account. Signing in is only needed to sit a final test, so the score is kept on your profile.

Linear Algebra

A matrix is a transformation: vectors and spaces, bases and rank, determinants and eigenvectors, and what each one does to the space it acts on.

Two equations, and then two thousand

Solving two equations in two unknowns is school algebra, and solving two thousand equations in two thousand unknowns is a different activity entirely, which is what this subject exists to make possible.

This course assumes the material of Mathematical Foundations: manipulating algebraic expressions, functions and their graphs, coordinates in the plane, and enough trigonometry to read cosθ and sinθ off a unit circle. Nothing else is assumed. In particular, calculus is never used, and where a connection to it exists it is signposted and skippable.

What makes an equation linear

An equation is linear in the unknowns x1,x2,,xn when it can be written as

a1x1+a2x2++anxn=b

with the coefficients ai and the constant b being fixed numbers. Every unknown appears to the first power, alone, multiplied only by a number. That rules out x2, it rules out xy, and it rules out sinx, 1/x and x. Note that 3x+4y=12 qualifies, and so does 0x+0y=0, and so does 7x1-2x2+0x3=-1, where the missing unknown is present with coefficient zero.

This looks like a severe restriction, and it is worth being clear that it is one. Most equations that describe the world are not linear. What makes the restricted class worth an entire subject is a combination of three facts. Linear systems can actually be solved, exactly, by a procedure that always terminates. Many genuinely non-linear problems are linear when examined closely enough, which is why a bridge deflecting slightly under load, a circuit at small signal, and a chemical mixture at low concentration are all handled linearly. And problems that are hopelessly non-linear are usually attacked by solving a linear system repeatedly, which is what Newton's method, every finite element package and every step of training a neural network are doing underneath.

A system of linear equations is several of them at once, sharing their unknowns. A solution is an assignment of numbers to the unknowns that satisfies every equation simultaneously, not merely one of them. The entire difficulty is that word: simultaneously.

Two unknowns, and two lines

With two unknowns the whole situation is visible. The equation 2x+3y=7 is satisfied by infinitely many pairs (x,y), and plotted in the plane they form a straight line, which is why the equations are called linear in the first place. A second equation gives a second line. A solution of the system is a point on both lines, so solving the system means intersecting them.

Two distinct lines in a plane intersect in exactly one point unless they are parallel, in which case they meet nowhere, unless they are the same line, in which case they meet everywhere along it. Those are the only three possibilities, and no fourth case exists: two lines cannot meet in exactly two points. That fact is worth holding on to, because it survives intact into two thousand dimensions where nothing can be drawn.

Example. Solve 2x+3y=7 and 4x-y=7.

Multiply the second equation by 3 to get 12x-3y=21, and add it to the first, so that the y terms cancel: 14x=28, giving x=2. Substituting back into the second equation, 8-y=7, so y=1. Check both original equations: 2(2)+3(1)=7 and 4(2)-1=7. The lines cross at (2,1).

Now you. Solve 3x+2y=16 and x-y=2.

Answer

Multiply the second by 2 to get 2x-2y=4 and add: 5x=20, so x=4, and then y=x-2=2. Check: 3(4)+2(2)=16 and 4-2=2. The solution is (4,2).

Elimination

The method in that example, adding a multiple of one equation to another so that an unknown vanishes, is the whole of it. Scaled up and made systematic it is called Gaussian elimination, though it appears in the Chinese Nine Chapters on the Mathematical Art around two thousand years before Gauss, worked with counting rods on a board.

Three operations are permitted, and each is reversible, which is what guarantees that they never gain or lose a solution. Any equation may be multiplied by a non-zero number. Any multiple of one equation may be added to another. Any two equations may be swapped. The goal is to reach a triangular form, in which the first equation involves all the unknowns, the second has lost the first unknown, the third has lost the first two, and so on down, at which point the last equation contains one unknown and the rest fall out by back substitution.

Take a system of three:

2x+y-z=8
-3x-y+2z=-11
-2x+y+2z=-3

Use the first equation to remove x from the other two. Adding 1.5 times the first to the second gives 0x+0.5y+0.5z=1. Adding the first to the third gives 0x+2y+z=5. The first unknown is now confined to the first equation.

Now use the new second equation to remove y from the third. Subtracting 4 times (0.5y+0.5z=1) from (2y+z=5) gives 0y-z=1, so z=-1.

Back substitute. From 0.5y+0.5z=1 with z=-1: 0.5y=1.5, so y=3. From the first equation, 2x+3-(-1)=8, so 2x=4 and x=2. The solution is (2,3,-1), and substituting it into all three original equations gives 8, -11 and -3 as required.

Two features of that calculation matter more than the answer. It was mechanical: at no point was ingenuity required, only a decision about which equation to use to clear which unknown. And it terminated: there is no possibility of the procedure wandering, because each step permanently removes one unknown from one equation and the supply of both is finite.

Example. Solve x+2y+z=6, 2x+y-z=1 and x-y+2z=5 by elimination.

Subtract 2 times the first from the second: -3y-3z=-11. Subtract the first from the third: -3y+z=-1. Now subtract the second of these from the third: 4z=10, so z=2.5. Then -3y=-1-z=-3.5, so y=7/61.1667, and x=6-2y-z=6-2.3333-2.5=1.1667. Check the second equation: 2(1.1667)+1.1667-2.5=1.0, as required.

Now you. Solve x+y+z=6, 2y+5z=-4 and 2x+5y-z=27.

Answer

Subtract 2 times the first from the third: 3y-3z=15, so y-z=5. Combine with 2y+5z=-4: substituting y=z+5 gives 2z+10+5z=-4, so 7z=-14 and z=-2. Then y=3 and x=6-3+2=5. The solution is (5,3,-2), which satisfies all three.

The three outcomes

Elimination cannot fail, but it can end somewhere other than a triangle, and there are exactly two ways for that to happen.

Take x+2y=4 and 2x+4y=7. Subtracting twice the first from the second gives 0x+0y=-1, which no assignment of x and y can satisfy. The system is inconsistent and has no solution. Geometrically the two lines have the same slope and different intercepts: they are parallel, and never meet.

Now change one digit: x+2y=4 and 2x+4y=8. The same step gives 0x+0y=0, which every pair satisfies. The second equation was the first one in disguise, carrying no information, and the system is left with one genuine equation in two unknowns. Setting y to any value t gives x=4-2t, so the solutions form a whole line: (4,0), (2,1), (0,2) and infinitely many more. The system is underdetermined.

So a linear system has no solution, exactly one, or infinitely many. It can never have exactly two, or exactly seventeen. The reason is easy to see and worth seeing now: if p and q are both solutions then so is every point on the line joining them, because averaging two solutions of a1x1++anxn=b in any weighted way that sums to one gives b again. Two solutions therefore drag a continuum in with them. Later lessons make this precise, and give the solution set a name and a dimension.

Example. Classify 3x-6y=9 and -x+2y=-3.

Add 3 times the second to the first: 0=0. The second equation is -1/3 times the first, so there is one genuine equation, x-2y=3, and infinitely many solutions: x=3+2t, y=t. Two of them are (3,0) and (5,1), and both satisfy the original pair.

Now you. Classify 4x-2y=5 and -6x+3y=1.

Answer

Multiply the first by 1.5: 6x-3y=7.5. Adding the second gives 0=8.5, which is false, so the system is inconsistent and has no solution. The two lines both have slope 2 and different intercepts.

What it costs

The reason a subject is needed rather than a technique is that n grows. Clearing the first unknown from n-1 equations of n+1 numbers each costs roughly n2 multiplications, and repeating for each unknown in turn totals about n3/3 multiplications and as many additions. For n=1000 that is 3.3×108 operations, a fraction of a second on any laptop. For n=5000 it is 4.2×1010, about forty seconds at a billion operations per second. For n=106, the size of system a serious engineering simulation produces, it is 3.3×1017, which is out of reach by brute force and is solved instead by methods that exploit the structure of the particular matrix, most of whose entries are zero.

Compare the alternative that school sometimes teaches for small systems, Cramer's rule, which expresses each unknown as a ratio of determinants. Computing an n by n determinant by the naive expansion costs about n! multiplications. For n=20 that is 2.4×1018 operations, seventy-seven years at a billion per second, against 2700 operations for elimination. Cramer's rule is a theoretical statement, not an algorithm, and this course will treat it as one.

Example. Roughly how many multiplications does elimination need for n=200, and how does that compare with n=2000?

Using n3/3: for n=200 it is 8×106/3=2.7×106. For n=2000 it is 8×109/3=2.7×109. Ten times the unknowns costs a thousand times the work, because the count is cubic.

Now you. A solver manages 2×109 multiplications per second. Roughly how long does it take on a system with n=5000?

Answer

n3/3=1.25×1011/3=4.17×1010 multiplications, so about 4.17×1010/2×10921 seconds. Doubling to n=10000 would take eight times as long, near three minutes.

The unknowns were never used

Look back at the elimination worked above and ask which symbols did any work. The letters x, y and z were carried through every line and never once entered a calculation. All the arithmetic happened to the coefficients, and the letters were placeholders keeping the columns aligned. Written without them, the first system is nothing but a rectangle of numbers, with rows (2,1,-1), (-3,-1,2) and (-2,1,2), together with the right hand side (8,-11,-3).

That rectangle is a matrix, and the course to come is largely about taking it seriously as an object in its own right rather than as shorthand for a system. Two conventions are fixed now and used for the rest of the subject. A vector is a column of numbers, written in round brackets as (8,-11,-3). A matrix is written as the list of its columns, so A=[(2,-3,-2),(1,-1,1),(-1,2,2)] is the coefficient matrix of that system, whose first column collects the coefficients of x from all three equations. When elimination needs to talk about a row it will say so explicitly.

Writing the system by columns exposes something the row form hides. The three equations, taken together, say precisely that

x(2,-3,-2)+y(1,-1,1)+z(-1,2,2)=(8,-11,-3)

where the multiplications and additions happen component by component. Solving is therefore asking what amounts of the three column vectors, added together, produce the target vector. That reading is the door into the geometry, and it turns the three outcomes above into three pictures rather than three algebraic accidents.

Honest limits

Exact arithmetic makes elimination flawless, and computers do not have exact arithmetic. If a pivot, the coefficient being divided by, is very small, dividing by it magnifies whatever rounding error the entry already carried, and the answer can come out wrong in every digit while the procedure reports no difficulty. The standard defence is partial pivoting: before clearing a column, swap in the row whose entry in that column is largest in absolute value. This costs almost nothing and, as James Wilkinson established in his backward error analysis around 1961, makes elimination reliable in practice, though contrived matrices that defeat it do exist. Every numerical library performs the swap by default.

There is also a limit worth naming at the start. Everything in this subject is exact and complete for the linear class, and the class really is a restriction. Nothing here will solve x2+y2=1. What the subject offers in exchange is that within its class, questions have answers and the answers can be computed and checked.

The next lesson takes up the column vectors that the coefficient matrix turned out to consist of, and asks what they are and what can be done to them.

Vectors

A column of numbers can be read as an arrow in space, and the two readings support exactly the same arithmetic, which is what makes the geometry of the previous lesson available to systems of any size.

The previous lesson ended by writing a system of three equations as a statement about three columns of coefficients, x(2,-3,-2)+y(1,-1,1)+z(-1,2,2)=(8,-11,-3). Two things happened to those columns there: they were multiplied by numbers, and they were added. This lesson takes those two operations as the definition of the objects, and then shows that measurement, length and angle and perpendicularity, comes from one further product that is not part of the definition at all.

An arrow and a list

A vector in the plane can be pictured as an arrow with a length and a direction, and represented by the pair of numbers saying how far it goes across and how far up: (3,4) is three to the right and four up. The arrow is not anchored anywhere. An arrow from (1,1) to (4,5) and an arrow from the origin to (3,4) are the same vector, because both are three across and four up, and it is convenient to draw every vector from the origin so that vectors and points can be identified.

In three dimensions the same works with triples, and beyond three the picture stops but the arithmetic does not. A vector in Rn is an ordered list of n real numbers, and n can be a million. This is not an abstraction for its own sake. A greyscale image of 1000 by 1000 pixels is a vector in R1000000, one coordinate per pixel. A month of daily closing prices for thirty stocks is a vector in R900. The word "direction" is unvisualisable in those spaces and remains perfectly well defined.

Two vectors are equal when every component matches. The zero vector 0 has every component zero, and it is the one vector with no direction. Vectors are written in bold, v, and their components with subscripts, so v=(v1,v2,,vn). Throughout this course a vector written in round brackets is a column, which matters from the lesson on matrices onward.

Two operations, and only two

Addition works component by component: (1,2)+(3,1)=(4,3). Geometrically it is tip to tail. Draw the first arrow, start the second where the first ended, and the sum runs from the original start to the final tip. Equivalently, complete the parallelogram with the two arrows as sides and take its diagonal. That the two constructions agree is the statement that u+v=v+u, which is obvious from the components and not obvious from the picture.

Scalar multiplication multiplies every component by a number: 2(1,2)=(2,4) and -0.5(4,3)=(-2,-1.5). The number is called a scalar to distinguish it from a vector. Geometrically, multiplying by c stretches the arrow by a factor |c|, and reverses it when c is negative. All the scalar multiples of one non-zero vector, taken together, form an infinite straight line through the origin.

Subtraction is not a third operation, being u+(-1)v, and it is worth reading geometrically: u-v is the arrow from the tip of v to the tip of u. That reading is used constantly, because the vector between two points is the difference of their position vectors.

There is deliberately no multiplication of two vectors in this list, and no division at all. The reason is that the operations are chosen to be exactly those that a system of linear equations performs, and the definition is worth stating in that spirit: a vector space is any set on which addition and scalar multiplication are defined and obey eight rules, that addition is commutative and associative, that a zero exists and each element has a negative, that scaling distributes over both kinds of sum, that (cd)v=c(dv), and that 1v=v. Lists of n numbers satisfy them. So do polynomials of degree at most five, which can be added and scaled and form a space of a size worked out two lessons from now. So do all real-valued functions on an interval, and so do the solutions of a differential equation like y′′+y=0. Every result in this course rests on the eight rules alone, so every result applies to all of those, which is the return on the abstraction.

Example. With u=(2,-1,3) and v=(1,4,-2), compute 3u-2v.

Scale first: 3u=(6,-3,9) and 2v=(2,8,-4). Subtract component by component: (6-2,-3-8,9+4)=(4,-11,13).

Now you. With the same u and v, compute u+2v and check that it equals (4,7,-1).

Answer

2v=(2,8,-4), so u+2v=(2+2,-1+8,3-4)=(4,7,-1). The check is componentwise, and each one has to work independently.

Length

Nothing said so far measures anything. Length has to be added, and in the plane Pythagoras supplies it: the arrow (3,4) is the hypotenuse of a right triangle with legs 3 and 4, so its length is 9+16=5. In three dimensions apply Pythagoras twice, once in the base plane and once vertically, giving v12+v22+v32. The vector (1,2,2) has length 1+4+4=3 exactly.

In n dimensions the same formula is taken as the definition, since there is no triangle to appeal to:

v=v12+v22++vn2

The double bars distinguish it from the absolute value of a number, which it generalises. Length is never negative, and is zero only for the zero vector. Scaling behaves as the picture demands: cv=|c|v, because every component is multiplied by c and every square by c2.

A vector of length one is a unit vector, and dividing any non-zero vector by its own length produces one pointing the same way, an operation called normalising. This separates a vector into a direction and a magnitude, which is what makes it useful.

Example. Find the length of (5,-12) and the unit vector in its direction.

(5,-12)=25+144=169=13. Dividing gives (5/13,-12/13)=(0.3846,-0.9231), and as a check 0.38462+0.92312=0.1479+0.8521=1.0000.

Now you. Find the length of (2,3,6) and normalise it.

Answer

4+9+36=49=7, so the unit vector is (2/7,3/7,6/7)=(0.2857,0.4286,0.8571). Squaring and adding gives 0.0816+0.1837+0.7347=1.0000.

The dot product

Angles need one more construction, and it is the single most useful formula in the subject. The dot product of two vectors with the same number of components multiplies them componentwise and adds the results:

ab=a1b1+a2b2++anbn

The output is a number, not a vector, which is why it is also called the scalar product. For (1,2) and (3,1) it is 3+2=5. It is commutative, it distributes over addition, and it relates to length by aa=a2, straight from the definitions.

Its geometric meaning is not visible in that formula and has to be derived. Take two vectors a and b with angle θ between them. The three arrows a, b and b-a form a triangle, so the law of cosines from Mathematical Foundations gives

b-a2=a2+b2-2abcosθ

Now expand the left side algebraically instead. Since b-a2=(b-a)(b-a), distributing gives bb-2ab+aa, which is b2-2ab+a2. Setting the two expressions equal, the squared lengths cancel from both sides and what remains is

ab=abcosθ

So a formula built out of nothing but multiplication and addition of coordinates knows the angle. Rearranged, cosθ=ab/(ab), and this is taken as the definition of angle in dimensions too high to draw.

One consequence deserves its own name. Since cos90°=0, two non-zero vectors are orthogonal, meaning perpendicular, exactly when their dot product is zero. Checking perpendicularity is therefore a multiplication and an addition, with no trigonometry and no picture. Almost everything later in this course that involves a right angle is really this test being applied.

A second consequence is that |cosθ|1 forces |ab|ab, the Cauchy-Schwarz inequality, holding in every dimension. For (1,2) and (3,1) it reads 5510=7.071, with equality only when the vectors are parallel.

Example. Find the angle between (1,2) and (3,1).

The dot product is 1(3)+2(1)=5. The lengths are 5=2.2361 and 10=3.1623, whose product is 50=7.0711. So cosθ=5/7.0711=0.70711, and θ=45° exactly, since cos45°=1/2.

Now you. Find the angle between (2,-1) and (1,3).

Answer

The dot product is 2-3=-1, and the lengths are again 5 and 10, so cosθ=-1/7.0711=-0.14142 and θ=98.13°. The negative dot product is the signal that the angle is obtuse, which is worth recognising without computing the arccosine.

What the dot product measures

Physics fixed the meaning before linear algebra did. Work is force times distance only when the two point the same way, and in general the work done by a constant force F through a displacement d is Fd. Take a force (12,5) newtons dragging an object through a displacement (3,4) metres. The dot product is 36+20=56 joules. Checking against the other formula: the force has magnitude 13 N, the displacement 5 m, and the angle between them is 30.51°, so 13×5×cos30.51°=65×0.8615=56 J. The two routes agree, as the derivation says they must, and the second one shows what is happening: only the part of the force lying along the displacement does any work.

That reading, how much of one vector lies along another, is what the dot product measures. If u is a unit vector then au is exactly the length of the shadow a casts on u's line, signed so that a shadow falling the other way counts negative. Take a=(4,3) and u=(1,0): the dot product is 4, which is the x coordinate, which is the shadow on the horizontal axis. Coordinates are dot products with the axis directions, a fact that looks like a triviality here and becomes a labour-saving device in the lesson on orthogonality.

Projection

Make that precise for a general direction. Given b and a non-zero a, the projection of b onto a is the multiple of a that lies directly under b, meaning the multiple ca for which the leftover b-ca is perpendicular to a. That one condition determines c: orthogonality means a(b-ca)=0, so ab=caa and

c=abaa

with the projection itself being ca. Nothing was assumed about the dimension, so this works in R900 as readily as in the plane.

The projection splits b into two pieces, one along a and one perpendicular to it, and that decomposition is used everywhere from resolving forces on a slope to the least squares fitting three lessons ahead.

Example. Project b=(4,3) onto a=(2,1), and split b into parallel and perpendicular parts.

ab=8+3=11 and aa=4+1=5, so c=2.2 and the projection is 2.2(2,1)=(4.4,2.2). The leftover is (4-4.4,3-2.2)=(-0.4,0.8), and its dot product with a is -0.8+0.8=0, confirming the right angle. The two pieces sum back to (4,3).

Now you. Project b=(5,2) onto a=(1,3) and check the leftover is perpendicular.

Answer

ab=5+6=11 and aa=1+9=10, so c=1.1 and the projection is (1.1,3.3). The leftover is (3.9,-1.3), whose dot product with (1,3) is 3.9-3.9=0.

Honest limits

The dot product formula a1b1++anbn is not a property of the vectors alone: it assumes the coordinates are measured along axes that are themselves perpendicular and equally scaled. Write the same arrows in a slanted coordinate system and the componentwise formula stops giving the right angles. The lesson on change of basis returns to this, and orthogonal bases matter later precisely because they are the ones where the easy formula stays true.

Two other cautions. The cross product, which takes two vectors to a third, exists only in three dimensions and is not part of this course. And the dot product of two vectors of the same length is a poor measure of similarity when the vectors have very different magnitudes, which is why applied work usually normalises first and compares cosθ rather than the raw product.

Addition and scaling are now the whole toolkit, and length and angle sit on top of them. Applying those two operations to a fixed collection of vectors, over and over, generates everything the collection can reach, and the next lesson asks what that reachable set looks like and when one of the vectors in the collection is contributing nothing.

Linear combinations, span and independence

Adding and scaling are the only two operations available, so applying them repeatedly to a fixed set of vectors generates everything that set can reach, and a system of equations asks whether a particular target is reachable.

This lesson needs only the previous one: a vector is a list that can be added componentwise and multiplied by a number, and the two operations have a geometric reading as arrows joined tip to tail and arrows stretched. Everything below is those two operations applied several times.

One question instead of many equations

A linear combination of the vectors v1,,vk is any vector of the form

c1v1+c2v2++ckvk

with the ci any real numbers. Because only addition and scaling are used, that expression is the most general thing that can be built out of a set of vectors, and everything in the rest of the course is a linear combination of something.

Recall the system solved two lessons ago, 2x+y-z=8, -3x-y+2z=-11 and -2x+y+2z=-3. Read down the columns rather than along the rows and it says

x(2,-3,-2)+y(1,-1,1)+z(-1,2,2)=(8,-11,-3)

which is one vector equation in place of three scalar ones. The solution found there was x=2, y=3, z=-1, and substituting gives (4,-6,-4)+(3,-3,3)+(1,-2,-2)=(8,-11,-3), componentwise, as required.

The restatement is worth taking seriously, because it changes the question. Instead of asking which numbers satisfy three separate constraints, it asks: is the target vector a linear combination of the columns, and if so, in what amounts? That is a question about the columns, and it has a geometric answer.

Span

The span of a set of vectors is the set of all their linear combinations. It is written span{v1,,vk} and is best thought of as everything reachable from those vectors using the two permitted operations.

Some spans are easy to see. The span of a single non-zero vector v is {cv}, an infinite straight line through the origin in the direction of v. The span of the two vectors (1,0) and (0,1) is the whole plane, since (a,b)=a(1,0)+b(0,1) for any pair. The span of the empty set, and the span of {0}, is just the origin.

Two vectors in three-dimensional space usually span a plane through the origin: the combinations c1v1+c2v2 sweep out a flat sheet containing both arrows and the origin. But not always. If v2 happens to be a multiple of v1, say (2,4,6) against (1,2,3), then every combination is a multiple of v1 and the span collapses to a line. Two vectors span a plane when they point in genuinely different directions, and a line when they do not, and that distinction is the whole content of the next section.

Notice that a span always contains the origin, taking every coefficient zero, and that it is closed under the two operations: any combination of things in the span is again in the span. A span is therefore flat and unbounded, a line or a plane or a higher-dimensional analogue, always through the origin, and never a curve, a disc or a shifted plane.

Example. Is (4,5,6) in the span of (1,1,1) and (1,2,3)?

The question asks for numbers a and b with a(1,1,1)+b(1,2,3)=(4,5,6), which is three equations: a+b=4, a+2b=5, a+3b=6. Subtracting the first from the second gives b=1, so a=3. The third equation is a consistency check rather than a way of finding anything, and it holds: 3+3=6. So yes, and (4,5,6)=3(1,1,1)+1(1,2,3).

Now you. Is (7,8,9) in the same span, and is (4,5,7)?

Answer

For (7,8,9): a+b=7 and a+2b=8 give b=1 and a=6, and the third equation checks, 6+3=9. So it is in the span. For (4,5,7) the first two equations still give a=3 and b=1, but the third would need 3+3=7, which is false, so it is not in the span. Both points lie in three-dimensional space, and the span is only a plane, so most points miss it.

Dependence and independence

A set of vectors is linearly dependent when some non-trivial combination of them gives the zero vector, meaning

c1v1++ckvk=0

with at least one ci not zero. It is linearly independent when the only combination producing 0 is the one with every coefficient zero. The word "non-trivial" carries the whole definition: taking all the coefficients zero always works and says nothing.

The definition looks technical, and it is equivalent to something plainer: a set is dependent exactly when one of its members is a combination of the others. If c10 in a dependent relation, divide by it and rearrange to get v1=-(c2/c1)v2--(ck/c1)vk, so v1 is a combination of the rest. Conversely, if v1=d2v2++dkvk, move everything to one side to get a relation with c1=-1, which is certainly not zero. So dependence means redundancy: at least one vector adds nothing to the span, because it was already reachable from the others.

The zero-vector version of the definition is preferred despite being less intuitive, for two reasons. It treats all the vectors symmetrically, whereas "one is a combination of the others" invites the false belief that the guilty vector is identifiable, and it is directly a homogeneous system of the kind elimination solves.

Take v1=(1,1,2), v2=(2,1,3) and v3=(3,2,5). Adding the first two gives (3,2,5) exactly, so v1+v2-v3=0 with coefficients (1,1,-1), and the set is dependent. The span of all three is therefore no bigger than the span of the first two: a plane, not all of space.

Now take (1,0,0), (1,1,0) and (1,1,1). A combination is (c1+c2+c3,c2+c3,c3), and setting it to zero forces c3=0 from the last component, then c2=0 from the middle, then c1=0. Only the trivial combination works, so the set is independent and its span is all of R3.

Example. Are (1,2,3), (2,1,0) and (4,5,6) independent?

Set a(1,2,3)+b(2,1,0)+c(4,5,6)=0, which is a+2b+4c=0, 2a+b+5c=0 and 3a+6c=0. The last gives a=-2c. Substituting into the first, -2c+2b+4c=0, so b=-c. The second is then -4c-c+5c=0, satisfied automatically. Taking c=1 gives the relation -2(1,2,3)-(2,1,0)+(4,5,6)=0, which is checkable directly: 2(1,2,3)+(2,1,0)=(4,5,6). The set is dependent, and the third vector was redundant.

Now you. Are (1,0,1), (0,1,1) and (1,1,2) independent?

Answer

Adding the first two gives (1,1,2), which is the third, so (1,0,1)+(0,1,1)-(1,1,2)=0 and the set is dependent. Their span is the plane through the first two, not all of R3.

The three outcomes, seen

The first lesson found by algebra that a linear system has no solution, exactly one, or infinitely many. In the language of this lesson those are three statements about the columns of the system and the target vector b.

There is at least one solution exactly when b lies in the span of the columns. If the columns of a three by three system span all of R3, every target is reachable and the system is solvable whatever b is. If they span only a plane, then targets off that plane are unreachable, which is the inconsistent case: the algebra reported 0=-1, and the geometry says b was never in the span to begin with.

There is at most one solution exactly when the columns are independent. Suppose two different combinations both produce b. Subtracting them gives a combination equal to 0 whose coefficients are not all zero, since the two solutions differed, and that is dependence. Run the argument backwards and dependence produces infinitely many solutions: add any multiple of the dependence relation to a solution and it remains a solution, because the added part contributes 0.

So independence controls uniqueness and span controls existence, and the two are separate questions. The example above with (1,2,3), (2,1,0) and (4,5,6) has dependent columns, so any system built from them has either no solutions or an infinite line of them, and never one.

Example. The columns of a system are (1,2), (2,4) and (3,6), and b=(5,10). How many solutions?

Every column is a multiple of (1,2), so the span is the line through (1,2). The target (5,10)=5(1,2) is on that line, so solutions exist. The columns are wildly dependent, so there are infinitely many: x+2y+3z=5 is the single condition, and any (x,y,z) satisfying it works, for example (5,0,0) or (0,1,1).

Now you. Same three columns, but b=(5,11). How many solutions?

Answer

None. Every reachable vector has its second component exactly twice its first, and 1110. The target is off the line that the columns span, so no combination reaches it.

Counting

One counting fact does a great deal of work later, and it follows from elimination without any new machinery: any set of more than n vectors in Rn is dependent.

Here is why. Testing k vectors in Rn for dependence means solving c1v1++ckvk=0, which written out is n equations in k unknowns, one equation per component. Elimination clears one unknown per equation at most, so it can pin down at most n of the unknowns. If k>n then at least k-n unknowns are never pinned down and are free to take any value, and choosing a non-zero value for one of them produces a non-trivial relation. Since 0 is always a solution, the system is never inconsistent, so those free choices really do deliver solutions.

Three vectors in the plane are therefore always dependent, however they are chosen, and so are 1001 vectors in R1000. The converse direction is the same statement read the other way: fewer than n vectors can never span Rn, since n equations in k<n unknowns cannot be solvable for every right hand side. Between those two bounds sits the case of exactly n vectors, which is the useful one, and the next lesson is about it.

Honest limits

Independence is a property of a set, not of any individual vector in it. Saying "the third vector is dependent" is meaningless: in the worked example above, any one of the three could be written in terms of the other two, and nothing distinguishes a culprit.

The more serious limit is numerical. Independence is a yes or no question in exact arithmetic and a matter of degree in practice. The vectors (1,0) and (1,0.000001) are genuinely independent, and their span is genuinely the whole plane, but reaching (0,1) requires the combination -1000000(1,0)+1000000(1,0.000001), in which two enormous quantities nearly cancel. Any measurement error in the data is magnified by a factor of about a million. Sets like this are called ill-conditioned, and the number quantifying the trouble is introduced in the lesson on orthogonality. The theory presented here remains exactly true; it just stops being the only thing worth knowing.

A dependent set describes its span wastefully, using more vectors than the span requires. The next lesson removes the waste, and finds that what is left over has a size that does not depend on how the removing was done.

Subspaces, basis and dimension

A dependent set of vectors describes its span wastefully, and removing the waste leaves something whose size turns out not to depend on how the removing was done.

The previous lesson defined the span of a set of vectors as everything reachable from it by adding and scaling, and defined independence as the absence of redundancy. This lesson names the objects those spans are, gives each one a minimal description, and proves that any two minimal descriptions have the same length.

Subspaces

A subspace of Rn is a non-empty set V of vectors that is closed under both operations: if u and v are in V then so is u+v, and if v is in V then so is cv for every scalar c. Those two conditions are all of it, and they immediately force a third: taking c=0 shows every subspace contains 0.

The point of the definition is that a subspace is a place where the whole of linear algebra still works. You cannot fall out of it by doing arithmetic, so it can be treated as a small vector space in its own right.

Some sets qualify and some do not, and the failures are more instructive. The line through the origin in the direction (1,2) is a subspace: multiples of (1,2) add to multiples of (1,2). The line y=2x+1 is not, since it misses the origin, and also because (0,1) and (1,3) are on it while their sum (1,4) is not. The first quadrant, all (x,y) with x0 and y0, is closed under addition but not under scaling, since -1 times (1,1) leaves it, and that single failure disqualifies it. The set of vectors of length at most one fails for the same reason: doubling escapes it. Curved sets and bounded sets are never subspaces, and neither is anything that avoids the origin.

Two families of subspaces matter, and they will turn out to be the same family. First, every span is a subspace, directly from the definition, since a combination of combinations is a combination. Second, the solution set of a homogeneous system, one whose right hand side is 0, is a subspace: if u and v both satisfy every equation with zero on the right, so does u+v and so does cu, because each equation is built from adding and scaling. That is why homogeneous systems behave so much better than inhomogeneous ones, and why the solution set of x+2y-z=0 is a plane through the origin while the solution set of x+2y-z=4 is a parallel plane that is not a subspace at all.

Example. Is the set of (x,y,z) with x+2y-z=0 a subspace of R3?

Yes. If (x1,y1,z1) and (x2,y2,z2) both satisfy it, then adding the two equations shows the componentwise sum satisfies it too, and multiplying one equation by c shows c times a solution is a solution. The set is the solution set of a homogeneous equation, so it is a plane through the origin.

Now you. Is the set of (x,y) with xy=0, that is, the two coordinate axes together, a subspace of R2?

Answer

No. It is closed under scaling, since scaling a point on an axis keeps it on that axis, but not under addition: (1,0) and (0,1) are both in the set while (1,1) is not, because 1×10. Closure under both operations is required, and a set can pass one test and fail the other.

Basis

A basis of a subspace V is a set of vectors that is independent and spans V. The two requirements pull in opposite directions and meet in the middle: spanning demands enough vectors to reach everything, independence forbids any that are not needed. A basis is therefore a description of V with nothing missing and nothing wasted.

The standard basis of Rn is e1=(1,0,,0), e2=(0,1,0,,0) and so on. It spans because (a1,,an)=a1e1++anen, and it is independent because that same combination is zero only when every ai is zero. It is the basis that ordinary coordinates use, and its dominance is a convention rather than a fact about space, which is exactly the point of a later lesson.

Other bases of the same space are everywhere. In R2, the pair (1,1) and (1,-1) is a basis: independent, since neither is a multiple of the other, and spanning, since any (a,b) is a+b2(1,1)+a-b2(1,-1). So is (2,1) and (1,3). There are infinitely many bases of the plane, and no reason internal to the mathematics to prefer one.

The property that makes a basis worth having is uniqueness of coordinates. If v1,,vk is a basis of V, every vector in V can be written as a combination of them in exactly one way. Existence is the spanning half. Uniqueness comes from independence: suppose w=a1v1++akvk and also w=b1v1++bkvk. Subtracting gives (a1-b1)v1++(ak-bk)vk=0, and independence forces every coefficient to vanish, so ai=bi for each i. The two representations were the same one.

Those unique numbers are the coordinates of w with respect to the basis. Ordinary coordinates are the special case where the basis is the standard one, and the familiar statement that a point in the plane is a pair of numbers is really the statement that the plane has a basis of size two.

Example. Find a basis for the plane x+2y-z=0 and give its dimension.

Solve the equation: x is determined once y and z are chosen, since x=-2y+z. Taking y=1, z=0 gives (-2,1,0), and taking y=0, z=1 gives (1,0,1). Both satisfy the equation: -2+2-0=0 and 1+0-1=0. Every solution is y(-2,1,0)+z(1,0,1), so they span, and neither is a multiple of the other, so they are independent. The plane has a basis of two vectors.

Now you. Find a basis for the set of (x,y,z) in which all three components are equal.

Answer

Such a vector is (t,t,t)=t(1,1,1), so the single vector (1,1,1) spans the set, and one non-zero vector is always independent. The basis is {(1,1,1)} and the set is a line through the origin.

Dimension is well defined

Both bases of the plane given above have two elements, and both bases in the examples had the size the geometry suggested. That is not luck, and it needs proof, because a basis is a choice and there are infinitely many choices available.

Claim. If a subspace V is spanned by n vectors, then any n+1 vectors in V are dependent.

The proof reuses the counting argument from the previous lesson. Let s1,,sn span V, and take any w1,,wn+1 in V. Each wj is a combination of the si, say with coefficients a1j,,anj. Now ask for a dependence, c1w1++cn+1wn+1=0. Substituting and collecting the terms belonging to each si, the combination equals 0 whenever every one of the n quantities ai1c1++ai,n+1cn+1 is zero. That is a homogeneous system of n equations in n+1 unknowns. Elimination pins down at most n unknowns, so at least one is free, and choosing it non-zero gives a non-trivial solution. The wj are dependent.

The consequence is immediate. If B1 and B2 are both bases of V, with n and m elements, then B1 spans and B2 is independent, so mn by the claim, and reversing the roles gives nm. Hence n=m: every basis of V has the same number of elements, and that number is the dimension of V, written dimV.

Dimension is now a fact about the space rather than about anyone's description of it. A line through the origin has dimension one, a plane through the origin has dimension two, Rn has dimension n because the standard basis has n elements, and the subspace {0} has dimension zero, its basis being the empty set.

Spaces that are not arrows

Nothing in the definitions of subspace, basis and dimension mentioned arrows or coordinates. They used addition, scalar multiplication and the eight rules, so they apply verbatim to every vector space, and the useful ones are frequently not sets of arrows at all.

The polynomials of degree at most five form a vector space: adding two of them gives another, scaling one gives another, and the zero polynomial is the zero vector. A basis is 1,x,x2,x3,x4,x5, since every such polynomial is a unique combination of these, so the dimension is six, one more than the degree. The coordinates of 3x2-7 in that basis are (-7,0,3,0,0,0), which is exactly the list of coefficients: a polynomial is a vector whose components happen to be written next to powers of x.

The two by two matrices form a four-dimensional space, with a basis of the four matrices having a single entry equal to one. This is worth noticing because it means matrices are themselves vectors, and any statement proved about spans and independence applies to a collection of matrices.

The solutions of a differential equation like y′′+y=0 form a vector space, since a sum of solutions solves it and so does a multiple. A basis is cosx and sinx, so the dimension is two, and that is the real reason a second order equation carries exactly two arbitrary constants: the solution set is a two-dimensional subspace of the space of functions, and the constants are coordinates in it. The same idea explains the phrase "general solution" in every differential equations course.

Example. What is the dimension of the space of polynomials of degree at most three that vanish at x=0?

The full space has dimension four, with basis 1,x,x2,x3. Vanishing at zero means the constant term is zero, which removes exactly one basis element, leaving x,x2,x3. Those three are independent and span the set, so the dimension is three. Note the pattern: one linear condition removed one dimension, exactly as one equation cut R3 down to a plane.

Now you. Is the set of polynomials of degree at most three with p(1)=0 a subspace, and if so what is its dimension?

Answer

It is a subspace: if p(1)=0 and q(1)=0 then (p+q)(1)=0 and (cp)(1)=0. The condition p(1)=0 is one linear equation on the four coefficients, so it removes one dimension, leaving three. A basis is x-1, x2-1 and x3-1, each of which vanishes at x=1.

Trimming and extending

Two workhorse facts follow, and both are proved by the same move.

Every spanning set contains a basis. If a spanning set is dependent, one of its vectors is a combination of the others, so deleting it leaves the span unchanged. Repeat. The set is finite, so the process stops, and it stops exactly when no vector is redundant, which is independence.

Every independent set in V can be extended to a basis of V. If an independent set does not yet span V, some w in V is out of reach, and adding it keeps the set independent, since a dependence involving w would express w in terms of the others and put it in reach. Repeat. By the claim above the set can never exceed dimV elements, so the process stops, and it stops exactly when the set spans.

Together these give a useful shortcut: in a space of dimension d, any d independent vectors automatically span, and any d vectors that span are automatically independent. Once the count is right, one of the two conditions is enough to check.

Example. Express (2,-5,3) in the basis (1,-1,0), (1,0,-1) of the plane x+y+z=0.

First check the vector belongs there: 2-5+3=0, so it does. Solve a(1,-1,0)+b(1,0,-1)=(2,-5,3). The second component gives -a=-5, so a=5; the third gives -b=3, so b=-3; and the first is then the check, 5-3=2. The coordinates are (5,-3), so a vector with three ordinary components has just two coordinates in this basis, which is the dimension of the plane it lives in.

Now you. Express (7,4) in the basis (1,1), (1,-1) of R2.

Answer

Solving a+b=7 and a-b=4 gives a=5.5 and b=1.5. Check: 5.5(1,1)+1.5(1,-1)=(5.5+1.5,5.5-1.5)=(7,4). The same arrow that has standard coordinates (7,4) has coordinates (5.5,1.5) here, and nothing about the arrow changed.

Honest limits

Coordinates depend entirely on the basis, and a vector does not carry its coordinates around with it. The last example is the whole warning: (7,4) and (5.5,1.5) are the same arrow described by two people using different rulers. Software and textbooks alike suppress the basis because it is almost always the standard one, and the suppression becomes a bug the moment two bases are in play, which is what the lesson on change of basis is about.

The theory above assumes a finite spanning set exists. Spaces without one, such as all continuous functions on an interval, are infinite-dimensional, and there the word basis is used in a weaker sense involving convergent infinite sums, which needs analysis rather than algebra. Fourier series are that theory in action, and nothing in this course applies to them without care.

Finally, dimension is exact and discontinuous. Three vectors that lie in a plane span a two-dimensional space; nudge one of them by 10-9 out of the plane and the span is suddenly all of R3, though it is a very thin sort of three dimensions. Numerical work replaces dimension with a threshold on how thin, which the lesson on rank returns to.

There are objects, there are coordinates, and there is a well-defined notion of size. What is entirely missing is anything that moves: so far every vector has sat still. The next lesson introduces maps that respect both operations, and finds that such a map is completely pinned down by what it does to a basis.

Linear transformations

Everything so far has sat still, and the subject only becomes useful when something moves the vectors around.

The previous lessons built the objects: vectors, added and scaled, spanning subspaces that have a dimension and a basis. Nothing in them acts. This lesson introduces maps from one space to another, restricts them to the ones that respect the two operations, and finds that the restriction is so severe that such a map can be written down completely with a handful of numbers.

The definition, and what it rules out

A map T from Rn to Rm is linear when it satisfies two conditions for all vectors u,v and all scalars c:

T(u+v)=T(u)+T(v)T(cv)=cT(v)

In words: it does not matter whether you add before or after applying T, and it does not matter whether you scale before or after. The two together say T preserves linear combinations, T(au+bv)=aT(u)+bT(v), which is the form actually used in proofs.

An immediate consequence is T(0)=0: take c=0 in the second condition. A linear map cannot move the origin, and that alone rules out a large class of familiar operations.

Translation is the important casualty. The map T(x,y)=(x+1,y), sliding the plane one unit right, is not linear, because T(0,0)=(1,0)0. This is not a technicality to be regretted: translations are excluded on purpose, because including them would destroy the theory, and the practical fix is the affine trick mentioned at the end of this lesson.

Squaring fails too. For T(x,y)=(x2,y), compare T(2,0)=(4,0) with 2T(1,0)=(2,0). Scaling the input doubled the output in one place and quadrupled it in another, so the second condition fails. And a map can satisfy one condition while failing the other, so both must be checked.

What survives is a smaller class than intuition suggests, and it contains exactly the operations that stretch, rotate, reflect, shear, project and collapse, applied uniformly to the whole space. Geometrically, a linear map on the plane sends straight lines to straight lines, keeps the origin fixed, and sends a grid of parallel evenly spaced lines to another grid of parallel evenly spaced lines, though the grid may be tilted, stretched or flattened.

Example. Is T(x,y)=(2x-y,x+3y) linear?

Take u=(u1,u2) and v=(v1,v2). Then T(u+v)=(2(u1+v1)-(u2+v2),(u1+v1)+3(u2+v2)), and expanding and regrouping gives (2u1-u2,u1+3u2)+(2v1-v2,v1+3v2)=T(u)+T(v). Scaling works the same way, since every term carries exactly one factor of an input component. So it is linear, and the general rule is visible: a map whose output components are sums of the input components multiplied by constants, with no constant term, is linear.

Now you. Is T(x,y)=(x+y,xy) linear?

Answer

No. T(2,0)=(2,0) and T(0,2)=(2,0), so the sum of the outputs is (4,0), while T(2,2)=(4,4). Addition is not preserved. The second component multiplies two input components together, which is exactly what linearity forbids.

A map is fixed by what it does to a basis

Here is the theorem that makes the subject computational. Write any vector in the plane in the standard basis, v=(x,y)=xe1+ye2 where e1=(1,0) and e2=(0,1). Applying a linear T and using both conditions,

T(v)=T(xe1+ye2)=xT(e1)+yT(e2)

The right hand side involves T only at the two basis vectors. So if you know where T sends e1 and where it sends e2, you know where it sends everything, with no further information required. In Rn the same argument uses n basis vectors, and in any subspace it uses a basis of that subspace.

This is a strong statement. A general function from the plane to the plane requires specifying two numbers for each of infinitely many points. A linear one requires four numbers in total.

Suppose T(e1)=(3,1) and T(e2)=(-1,2). Then T(4,5)=4(3,1)+5(-1,2)=(12-5,4+10)=(7,14), and every other value of T is available the same way.

The matrix of a transformation

Record those images as the columns of an array, and the array is the matrix of T. Following the convention fixed in the first lesson, a matrix is written as the list of its columns, so the map above has matrix

A=[(3,1),(-1,2)]

whose first column is T(e1) and whose second is T(e2). This is the single most useful sentence in the subject: the columns of a matrix are the images of the basis vectors. Read a matrix that way and its geometry is visible without any computation.

The product Ax is then defined to be exactly what the theorem says T(x) is:

Ax=x1(column 1)+x2(column 2)+

a linear combination of the columns with the components of x as the weights. Taking A=[(2,1),(-1,3)] and x=(4,2): 4(2,1)+2(-1,3)=(8-2,4+6)=(6,10).

The same number can be computed the other way round, taking one output component at a time: the ith component of Ax is the ith row of A dotted with x. Here the first row is (2,-1), giving 8-2=6, and the second row is (1,3), giving 4+6=10. The row method is how the arithmetic is usually organised, and the column method is what it means. Both give the same answer, because both are the same sum of products with the terms gathered differently.

An m by n matrix has n columns, each of length m, and represents a map from Rn to Rm: it eats vectors with n components and produces vectors with m. Note the order, which trips everyone at first: the number of columns is the dimension of the input space.

With this, the very first lesson's system becomes Ax=b, and the whole subject is one notation. Solving a system asks which input A sends to a given output.

Example. A linear map doubles every vector and then rotates it a quarter turn anticlockwise. What is its matrix?

Follow the basis vectors. e1=(1,0) doubles to (2,0), and a quarter turn anticlockwise sends it to (0,2). e2=(0,1) doubles to (0,2), and turning sends it to (-2,0). So the matrix is [(0,2),(-2,0)]. Test it on (3,1): the formula gives 3(0,2)+1(-2,0)=(-2,6), and by hand, doubling gives (6,2) and a quarter turn sends (6,2) to (-2,6).

Now you. A linear map reflects in the horizontal axis and then multiplies every length by three. What is its matrix?

Answer

e1=(1,0) is unmoved by the reflection and becomes (3,0). e2=(0,1) reflects to (0,-1) and becomes (0,-3). The matrix is [(3,0),(0,-3)]. Applied to (2,5) it gives 2(3,0)+5(0,-3)=(6,-15), which is the reflection (2,-5) tripled.

A catalogue of plane transformations

Every entry below is obtained the same way, by asking where e1 and e2 go. None of them needs to be memorised.

Scaling. Stretching by a horizontally and b vertically sends e1 to (a,0) and e2 to (0,b), giving [(a,0),(0,b)]. With a=b this is a uniform scaling, and with a=b=1 it is the identity matrix I=[(1,0),(0,1)], which leaves every vector alone.

Rotation. Turn the plane anticlockwise by θ. The vector e1 lands on the unit circle at angle θ, which is (cosθ,sinθ). The vector e2 starts a quarter turn ahead of e1 and stays a quarter turn ahead, landing at angle θ+90°, which is (-sinθ,cosθ). So

Rθ=[(cosθ,sinθ),(-sinθ,cosθ)]

For θ=90° this is [(0,1),(-1,0)], matching the quarter turn used above. That entire derivation is two sentences of trigonometry, which is why the rotation matrix is worth deriving rather than remembering.

Shear. Fix the horizontal axis and slide everything else sideways in proportion to its height: e1 stays at (1,0) and e2 moves to (k,1). The matrix is [(1,0),(k,1)]. With k=1 the point (2,3) goes to 2(1,0)+3(1,1)=(5,3): the height is unchanged and the horizontal displacement equals the height. This is what italic type does to letters.

Projection. Flatten the plane onto the horizontal axis: e1 stays and e2 goes to 0, giving [(1,0),(0,0)]. Information is destroyed here, since every point with the same x has the same image, and that irreversibility is the subject of two lessons from now.

Reflection. Reflecting in the line y=x swaps the axes, so e1(0,1) and e2(1,0), giving [(0,1),(1,0)]. For a general line through the origin at angle θ, reflecting sends e1 to angle 2θ and e2 to angle 2θ-90°, giving [(cos2θ,sin2θ),(sin2θ,-cos2θ)]. Setting θ=45° recovers the swap, since cos90°=0 and sin90°=1.

Example. Rotate (2,0) by 30° and confirm the length is unchanged.

The matrix is [(cos30°,sin30°),(-sin30°,cos30°)]=[(0.8660,0.5000),(-0.5000,0.8660)]. Applying it, 2(0.8660,0.5000)+0()=(1.7321,1.0000). The length is 3+1=2, unchanged, as a rotation demands. The exact answer is (3,1).

Now you. Rotate (0,3) by 60°.

Answer

Only the second column contributes: 3(-sin60°,cos60°)=3(-0.8660,0.5000)=(-2.598,1.500). The length is 6.750+2.250=9=3, unchanged. The exact answer is (-33/2,3/2).

Why the restriction pays

Linearity is what makes a transformation knowable from finitely many measurements, and the consequences run further than convenience.

Because T preserves combinations, it maps subspaces to subspaces: the image of a line through the origin is a line through the origin or the single point 0, and the image of a plane is a plane, a line or a point. Nothing bends, and nothing that was flat becomes curved.

Because T is determined on a basis, two maps agreeing on a basis are the same map everywhere, which is the standard way of proving that two matrices are equal. And because the matrix is just a list of images, building a transformation to specification is a matter of writing down where you want the basis to go, which is how every rotation in a graphics engine and every filter in signal processing is constructed.

The catalogue also shows what to watch for. Rotations and reflections preserve length; scalings and shears do not; projections destroy information. Those distinctions get numbers attached to them in the next three lessons.

Honest limits

Translation is not linear, and yet moving objects around is most of what computer graphics does. The standard fix is to embed the plane in three dimensions as the slice z=1, where a translation of the plane becomes a shear of the larger space, which is linear. Points then carry an extra coordinate, called homogeneous coordinates, and this is why graphics hardware works with four by four matrices for three-dimensional scenes: three dimensions of geometry plus one for the trick. Maps of the form T(x)=Ax+b are called affine, and they are the ones that preserve straight lines without fixing the origin.

Second, the matrix of a map depends on the basis used to write it down. Everything above used the standard basis silently. The same transformation gets a different matrix in a different basis, and choosing a basis that makes the matrix simple is the whole strategy of the last third of this course.

Third, real data is rarely linear, and calling a model linear is a claim that can be wrong. Doubling the dose does not always double the effect. The usual defence is that a smooth relationship is approximately linear over a small enough range, which is exactly what a derivative asserts, and the approximation fails outside that range without any warning from the algebra.

One transformation is now four numbers. Two transformations applied in turn are also a transformation, so it too has four numbers, and asking how to compute them from the original eight is what defines matrix multiplication in the next lesson.

Matrices and their product

Two transformations applied one after the other are again a transformation, so it has a matrix of its own, and working out what that matrix is defines multiplication.

The previous lesson established the fact this one rests on: a linear map is determined by where it sends the basis vectors, and the matrix of the map is the list of those images, written as columns. So A=[(3,1),(-1,2)] sends e1 to (3,1) and e2 to (-1,2), and Ax is the combination of the columns weighted by the components of x.

Deriving the product

Let A and B be matrices, and consider doing B first and then A. The composite map sends x to A(Bx), and it is linear, since a composition of maps that each preserve combinations preserves combinations. Being linear, it has a matrix, which is written AB and read right to left: B acts first.

Finding that matrix requires no new idea, only the rule that a matrix is the list of the images of the basis vectors. Column j of AB is the image of ej under the composite, which is A(Bej). But Bej is column j of B. So:

Column j of AB is A applied to column j of B.

That is the definition of matrix multiplication, and every other description of it is this one rearranged. Since A applied to a vector takes the dot product of each row of A with that vector, the entry in row i and column j of AB is row i of A dotted with column j of B, which is the rule usually taught first and which looks arbitrary until it is seen to come from composition.

Take A=[(2,1),(-1,3)] and B=[(1,4),(2,0)]. Column one of AB is A(1,4)=1(2,1)+4(-1,3)=(-2,13). Column two is A(2,0)=2(2,1)=(4,2). So AB=[(-2,13),(4,2)]. Checking one entry by the row rule: row one of A is (2,-1), and dotted with column one of B, which is (1,4), it gives 2-4=-2, matching.

The shape rule now explains itself. To form AB, the vectors that B produces must be vectors that A can eat, so the number of rows of B must equal the number of columns of A. An m by n matrix times an n by p matrix gives an m by p matrix, and any other combination is not a failure of arithmetic but a request to feed a map something it does not take.

Example. With A=[(2,1),(-1,3)] and B=[(1,4),(2,0)], compute BA.

Column one of BA is B applied to column one of A, that is B(2,1)=2(1,4)+1(2,0)=(4,8). Column two is B(-1,3)=-1(1,4)+3(2,0)=(5,-4). So BA=[(4,8),(5,-4)], which is nothing like AB=[(-2,13),(4,2)].

Now you. With C=[(1,2),(0,1)] and D=[(3,0),(1,1)], compute CD.

Answer

Column one is C(3,0)=3(1,2)+0(0,1)=(3,6). Column two is C(1,1)=1(1,2)+1(0,1)=(1,3). So CD=[(3,6),(1,3)].

Order matters

Multiplication of numbers is commutative and multiplication of matrices is not, and this is a feature rather than a defect: composing operations in the other order genuinely gives a different result, and the algebra had better say so.

Take R, a quarter turn anticlockwise, with matrix [(0,1),(-1,0)], and S, the shear [(1,0),(1,1)]. Then RS means shear first, and its columns are R(1,0)=(0,1) and R(1,1)=(-1,1), so RS=[(0,1),(-1,1)]. Meanwhile SR means turn first, with columns S(0,1)=(1,1) and S(-1,0)=(-1,0), giving SR=[(1,1),(-1,0)].

The two differ, and the difference is visible in a single vector: RS sends (1,0) to (0,1), while SR sends it to (1,1). Anyone can reproduce this with a book. Rotate it a quarter turn about the vertical axis and then a quarter turn about the horizontal one, then start again and do the two in the opposite order: the book ends up in two different orientations. Three-dimensional rotations do not commute, and the matrices that represent them must fail to commute in exactly the same pattern.

What does survive is associativity: (AB)C=A(BC), always. No calculation is needed, because both sides describe the map "do C, then B, then A", and function composition is associative by its nature. Proving it from the entry formula takes half a page of index manipulation and produces less understanding. Distributivity, A(B+C)=AB+AC, follows from linearity in the same way, addition of matrices being entry by entry.

The identity I=[(1,0),(0,1)] satisfies AI=IA=A, since it does nothing before or after anything else. And powers make sense for square matrices: A2=AA is the map applied twice. Shearing by k and shearing by k again gives [(1,0),(2k,1)], a shear by 2k, which is the algebra confirming that two equal slides compose into a double slide.

What composition proves

Because the product means composition, computing a product sometimes proves a theorem in trigonometry for free.

Rotating by β and then by α must be the same as rotating by α+β. Write the two matrices out, using the rotation matrix derived in the previous lesson. Column one of RαRβ is Rα applied to (cosβ,sinβ), which is

cosβ(cosα,sinα)+sinβ(-sinα,cosα)

that is, (cosαcosβ-sinαsinβ,sinαcosβ+cosαsinβ). But that column must be the first column of Rα+β, namely (cos(α+β),sin(α+β)). Comparing components gives both angle addition formulas at once. Anyone who has forgotten which sign goes where can rebuild them from the geometry in a minute.

Example. With R the quarter turn and S the shear above, compute R2 and identify it.

Column one is R(0,1)=(-1,0) and column two is R(-1,0)=(0,-1), so R2=[(-1,0),(0,-1)], which is -I. Two quarter turns make a half turn, and a half turn negates every vector.

Now you. Compute S3 for the shear S=[(1,0),(1,1)].

Answer

S2=[(1,0),(2,1)] from the doubling rule above, and S3=S2S has columns S2(1,0)=(1,0) and S2(1,1)=1(1,0)+1(2,1)=(3,1). So S3=[(1,0),(3,1)], a shear by 3, as three equal slides should be.

Zero products and other surprises

The algebra of matrices departs from the algebra of numbers in a second way, which is worth meeting deliberately rather than discovering in the middle of a proof.

Let P=[(1,0),(0,0)], the projection onto the horizontal axis, and Q=[(0,0),(0,1)], the projection onto the vertical. Neither is the zero matrix. Their product is: column one of PQ is P(0,0)=0, and column two is P(0,1)=0, so PQ is the zero matrix, and so is QP. Geometrically this is obvious once seen. Q flattens everything onto the vertical axis, and P then flattens the vertical axis onto the origin, so the composite destroys everything.

The consequence is that AB=0 does not imply that A or B is zero, and therefore that cancellation is illegal: from AB=AC you may not conclude B=C. The offending matrices are exactly those that collapse something, which the lesson on determinants identifies precisely.

A second surprise: P satisfies P2=P, since projecting twice is the same as projecting once. Among numbers only 0 and 1 do that, and among matrices there are infinitely many such idempotents, one for every projection.

Transpose

The transpose AT swaps rows and columns, so the columns of A become the rows of AT. If A=[(2,1),(-1,3)], its rows are (2,-1) and (1,3), so AT=[(2,-1),(1,3)]. Transposing an m by n matrix gives an n by m one, and transposing twice returns the original.

Two facts about it are used constantly. First, the dot product is a matrix product in disguise: ab=aTb, a one by n matrix times an n by one matrix, giving a single number. Second, the transpose reverses products, (AB)T=BTAT. The reason is visible through the dot product: for all vectors, (ABx)y=(Bx)(ATy)=x(BTATy), and the matrix that behaves this way on every pair of vectors is unique. A matrix with A=AT is symmetric, which requires it to be square and which turns out to be the best-behaved case in the whole subject, as the final lesson shows.

Example. Verify (AB)T=BTAT for A=[(2,1),(-1,3)] and B=[(1,4),(2,0)].

AB=[(-2,13),(4,2)] from above, whose rows are (-2,4) and (13,2), so (AB)T=[(-2,4),(13,2)]. Now BT=[(1,2),(4,0)] and AT=[(2,-1),(1,3)], and BTAT has column one BT(2,-1)=2(1,2)-1(4,0)=(-2,4) and column two BT(1,3)=1(1,2)+3(4,0)=(13,2). The two agree.

Now you. Is the product of two symmetric matrices always symmetric?

Answer

No. (AB)T=BTAT=BA when both are symmetric, and BA equals AB only if the two commute. For a concrete failure take A=[(1,0),(0,0)] and B=[(0,1),(1,0)], both symmetric: AB has columns A(0,1)=(0,0) and A(1,0)=(1,0), so AB=[(0,0),(1,0)], whose transpose is [(0,1),(0,0)], a different matrix.

What it costs

Multiplying two n by n matrices by the definition takes n multiplications per entry and there are n2 entries, so n3 multiplications in total. For n=1000 that is 109 operations, about a second at a billion per second, and for n=10000 it is 1012, which is why the size of the matrices in a machine learning model is a budget rather than a detail.

The exponent three is not forced. In 1969 Volker Strassen found a way to multiply two by two blocks using seven multiplications instead of eight, at the cost of extra additions, and applying it recursively gives an exponent of log27=2.807. At n=10000 that is 1.7×1011 instead of 1012, a real saving, though the constants and the numerical stability are worse and library implementations only switch to it for large matrices. Later work has pushed the exponent below 2.372, but those algorithms have constants so large that no practical matrix is big enough to benefit, and nobody knows the true minimum. The obvious lower bound is n2, since every entry must at least be read.

Honest limits

Matrix multiplication is associative and distributive but not commutative, and there is no division. The natural question is whether a given matrix can be undone at all, and the answer is sometimes no, as the projection above shows: once a vector has been flattened onto the horizontal axis, no transformation can recover which height it came from.

There is also a warning about notation. Because AB means "B first", chains of matrices read backwards relative to the order the operations happen, and this is a permanent source of error when translating a geometric description into a product. Some fields, including parts of computer graphics, avoid it by writing vectors as rows on the left instead, so that xAB means A first. Both conventions are in use, they produce transposed matrices, and mixing them silently gives wrong answers.

The next lesson takes up the undoing question. It turns out that a single number computed from the entries decides whether a square matrix can be inverted, and that the number has a plain geometric meaning: it is how much the transformation multiplies area.

Determinants and inverses

A transformation can be reversed only if nothing was lost on the way, and one number computed from a square matrix says whether anything was.

The previous lesson composed transformations and found that the projection [(1,0),(0,0)] flattens the plane onto a line, after which no transformation can recover which height a point came from. This lesson turns that observation into a test, and the test has a geometric meaning: how much the transformation multiplies area.

What area does under a transformation

Start with the unit square, whose corners are 0, e1, e2 and e1+e2, and whose area is one. A linear map sends e1 and e2 to the columns of its matrix, and sends the fourth corner to the sum of those columns, since it preserves addition. So the unit square becomes the parallelogram spanned by the two columns.

Every other region follows, because a linear map treats the whole plane uniformly. Any shape can be approximated by small squares from a fine grid, each square becomes a small parallelogram of the same shape and size as every other, and areas add. So a single number, the area of the image of the unit square, gives the factor by which every area is multiplied. That number is the determinant.

Compute it for the matrix with columns u=(a,c) and v=(b,d), taking all four entries positive for the picture. Enclose the parallelogram in the rectangle from 0 to (a+b,c+d), of area (a+b)(c+d), and remove what is not the parallelogram: two triangles of area 12ac, two triangles of area 12bd, and two rectangles of area bc. That leaves

(a+b)(c+d)-ac-bd-2bc=ad-bc

after cancelling. So the determinant of a two by two matrix is

detA=ad-bc

where, in the column notation of this course, A=[(a,c),(b,d)]. For A=[(3,1),(1,2)] that is 6-1=5: the unit square becomes a parallelogram of area five, and a circle of area π becomes an ellipse of area 5π.

Check the catalogue from two lessons ago against this. A shear [(1,0),(k,1)] has determinant 1, and a shear does preserve area, since it slides layers sideways without changing their height or width. A rotation [(cosθ,sinθ),(-sinθ,cosθ)] has determinant cos2θ+sin2θ=1, as a rigid motion must. A scaling [(a,0),(0,b)] has determinant ab, which is the area of the rectangle it makes. And the projection [(1,0),(0,0)] has determinant 0, because the image parallelogram is flat.

Example. Find the determinant of [(4,2),(1,3)] and say what it means.

Here a=4, c=2, b=1, d=3, so det=(4)(3)-(1)(2)=10. The transformation multiplies every area by ten. A triangle of area 0.5 becomes one of area 5.

Now you. Find the determinant of [(2,3),(4,6)].

Answer

det=(2)(6)-(4)(3)=12-12=0. The second column is exactly twice the first, so both basis vectors land on the same line and the unit square is flattened onto it, with no area left.

The sign

The formula ad-bc can come out negative, and area cannot, so the determinant is a signed area. The sign records orientation.

Going anticlockwise, e1 comes before e2. If the images keep that arrangement, the determinant is positive; if the images are swapped in sense, so that the shorter turn from the first column to the second is now clockwise, the determinant is negative and the map has flipped the plane over. Reflection in the line y=x has matrix [(0,1),(1,0)] and determinant 00-11=-1: area is preserved in size, as reflection should, and the sign reports the flip. Rotations, which do not flip, have determinant +1.

Orientation is not a curiosity. It is the difference between a left hand and a right hand, between a mould and the object it casts, and in three dimensions it is what distinguishes the two mirror forms of a chiral molecule.

The multiplication rule

Because the determinant is a scale factor, and scale factors multiply when transformations are composed, the following holds for all square A and B of the same size:

det(AB)=det(A)det(B)

Doing B then A multiplies area by detB and then by detA, so the total factor is the product, and the signs behave too, since two flips restore the original orientation. Proving this from the entry formula is an unpleasant expansion; proving it from what the determinant means is one sentence.

Check it once with numbers. With A=[(3,1),(1,2)], determinant 5, and B=[(2,0),(1,4)], determinant 8, the product AB has columns A(2,0)=(6,2) and A(1,4)=(7,9), so det(AB)=(6)(9)-(7)(2)=54-14=40=5×8.

Two consequences follow at once. If A has an inverse then det(A)det(A-1)=det(I)=1, so det(A-1)=1/det(A), and in particular an invertible matrix cannot have determinant zero. And if either factor has determinant zero then so does the product, which is the algebraic shadow of the fact that once something has been flattened, nothing later can unflatten it.

Zero means collapse

Everything now points at one criterion. The determinant is zero exactly when the image of the unit square has no area, which happens exactly when the two columns lie on a single line, which is exactly when the columns are linearly dependent. Chaining that to the previous lessons gives a list of statements about a square matrix A that are all true together or all false together: the determinant is non-zero; the columns are independent; the columns span the whole space; Ax=b has exactly one solution for every b; Ax=0 only for x=0; the transformation is reversible; the matrix has an inverse.

A matrix satisfying them is called invertible or non-singular, and one failing them singular. The word chosen by the third lesson, dependent, and the word chosen by this one, singular, are the same condition seen from two directions.

The failure is worth picturing rather than filing. When detA=0 the map squashes the plane onto a line or onto the origin, so many different inputs share an output, and no rule can send that output back to the right input, because the information identifying it is gone. Non-invertibility is not a defect of technique.

Three dimensions and beyond

In R3 the same definition applies to volume: the unit cube becomes the parallelepiped spanned by the three columns, and the determinant is its signed volume. The diagonal matrix [(1,0,0),(0,2,0),(0,0,3)] stretches by 1, 2 and 3 along the axes, giving a box of volume 6, which is its determinant.

For a general three by three the value is computed by cofactor expansion, which peels off one row at a time. Writing the rows as (a11,a12,a13) and so on,

detA=a11(a22a33-a23a32)-a12(a21a33-a23a31)+a13(a21a32-a22a31)

Each bracket is the two by two determinant left after deleting the row and column of the leading entry, and the signs alternate. The pattern continues in higher dimensions, an n by n determinant being a combination of n determinants of size n-1.

Take the coefficient matrix of the very first lesson's system, whose rows are (2,1,-1), (-3,-1,2) and (-2,1,2). Expanding along the first row: 2[(-1)(2)-(2)(1)]-1[(-3)(2)-(2)(-2)]+(-1)[(-3)(1)-(-1)(-2)], which is 2(-4)-1(-2)-1(-5)=-8+2+5=-1. Non-zero, so that system had exactly one solution, which is what elimination found.

The recursive method is a trap at scale: it costs about n! operations, which the first lesson already priced at seventy-seven years for n=20. The practical route is elimination, since adding a multiple of one row to another leaves the determinant unchanged, swapping two rows flips its sign, and the determinant of a triangular matrix is the product of its diagonal entries. Reducing to triangular form therefore delivers the determinant for the usual n3/3 operations.

Example. Compute the determinant of the matrix with rows (1,2,3), (0,1,4) and (5,6,0).

Expanding along the first row: 1[(1)(0)-(4)(6)]-2[(0)(0)-(4)(5)]+3[(0)(6)-(1)(5)], which is 1(-24)-2(-20)+3(-5)=-24+40-15=1. The matrix is invertible, and it scales volume by a factor of one while, as it happens, distorting shape considerably.

Now you. Compute the determinant of the matrix with rows (2,0,1), (1,3,2) and (0,1,1).

Answer

2[(3)(1)-(2)(1)]-0[(1)(1)-(2)(0)]+1[(1)(1)-(3)(0)]=2(1)-0+1(1)=3. Non-zero, so the matrix is invertible and it triples volume.

The inverse

The inverse of a square matrix A is the matrix A-1 with AA-1=A-1A=I, and it represents the transformation that undoes A. For the two by two case it can be derived rather than quoted.

Its first column is the vector x with Ax=e1, since the inverse must send e1 back where it came from. With A=[(a,c),(b,d)] that is the system ax1+bx2=1 and cx1+dx2=0. Eliminating gives x1=d/(ad-bc) and x2=-c/(ad-bc). The second column solves Ay=e2, giving y1=-b/(ad-bc) and y2=a/(ad-bc). So

A-1=1ad-bc[(d,-c),(-b,a)]

The determinant appears in the denominator, which is the algebra refusing to divide by zero exactly when the geometry says the map cannot be undone.

For A=[(3,1),(1,2)], with a=3, c=1, b=1, d=2 and determinant 5, the inverse is 15[(2,-1),(-1,3)]. Checking: the first column of AA-1 is A(0.4,-0.2)=0.4(3,1)-0.2(1,2)=(1.2-0.2,0.4-0.4)=(1,0), as required.

Beyond two by two there is no formula worth using, and the method is Gauss-Jordan elimination: write the matrix beside the identity, and apply row operations until the left side is the identity, at which point the right side is the inverse. Each operation is applied to both halves, so whatever sequence of operations turns A into I turns I into A-1. For the matrix with rows (1,2,3), (0,1,4) and (5,6,0) the result is the matrix with rows (-24,18,5), (20,-15,-4) and (-5,4,1), and multiplying the two gives the identity exactly, the determinant being 1 so that no fractions appear.

Inverses reverse under products, (AB)-1=B-1A-1, which is only common sense: to undo putting on socks and then shoes, take off the shoes first. The proof is one line, (AB)(B-1A-1)=A(BB-1)A-1=AA-1=I, using associativity.

Example. Invert A=[(3,1),(1,2)] and use it to solve Ax=(5,5).

The inverse is 15[(2,-1),(-1,3)] from above. Then x=A-1(5,5)=15[5(2,-1)+5(-1,3)]=15(10-5,-5+15)=15(5,10)=(1,2). Check against the original: A(1,2)=1(3,1)+2(1,2)=(5,5).

Now you. Invert B=[(2,1),(5,3)].

Answer

Here a=2, c=1, b=5, d=3, so detB=6-5=1 and B-1=[(3,-1),(-5,2)]. Check the first column of BB-1: B(3,-1)=3(2,1)-1(5,3)=(6-5,3-3)=(1,0).

Honest limits

Three warnings, all of which are routinely ignored to the cost of whoever ignores them.

Do not solve a system by computing an inverse. Gauss-Jordan costs roughly three times what plain elimination costs, and multiplying the inverse by b afterwards adds more error than solving directly. The expression x=A-1b is a statement about what the solution is, not an instruction for finding it, and numerical libraries that appear to be inverting are usually factorising instead.

Do not use the determinant as a test for singularity in floating point. Scale a perfectly well-behaved 100 by 100 matrix by 0.1 and its determinant is multiplied by 0.1100=10-100, which underflows to zero on a computer while the matrix remains as invertible as it ever was. Nearness to singularity is measured by the condition number instead, which compares the largest stretching factor with the smallest, and which the lesson on orthogonality returns to.

Do not expect Cramer's rule to be useful. It gives each unknown as a ratio of determinants, which is elegant and, computed naively, costs n! per unknown. It is a proof device, not an algorithm.

Two lessons ago a projection destroyed information, and this lesson gave the destruction a number: the determinant is zero. What it did not say is what exactly gets destroyed, or how much. A matrix can collapse three dimensions to two, or to one, or to a point, and all four cases have determinant zero. Measuring the survivors is the business of the next lesson.

Rank, null space and solution sets

A matrix with determinant zero flattens the space it acts on, and the useful questions are what exactly gets flattened and what is left.

The previous lesson gave a yes or no answer to invertibility. That is not enough, for two reasons. A three by three matrix can collapse space onto a plane, onto a line or onto the origin, and all three have determinant zero. And most matrices in practice are not square at all: fitting a straight line to fifty measurements produces a fifty by two matrix, which has no determinant and no inverse, and yet the system is not hopeless.

Two subspaces belong to every matrix

Let A be an m by n matrix, so it maps Rn to Rm.

The column space of A, written C(A), is the span of its columns. Since Ax is the combination of the columns weighted by the components of x, the column space is exactly the set of vectors of the form Ax: everything the transformation can reach. It lives in Rm, the output space.

The null space of A, written N(A), is the set of x with Ax=0: everything the transformation destroys. It lives in Rn, the input space.

Both are subspaces, by the test from the lesson on bases. The column space is a span, so it is one automatically. The null space is closed under both operations because A(u+v)=Au+Av=0+0 and A(cu)=cAu=0, which is linearity doing the work.

Take a concrete matrix and keep it for the rest of the lesson:

A=[(1,2,3),(2,4,6),(0,1,1)]

Its second column is twice its first, so the columns are dependent and the matrix is singular. The column space is the span of (1,2,3) and (0,1,1), which are not multiples of each other, so it is a plane in R3: the transformation squashes all of space onto that plane. For the null space, solve x1(1,2,3)+x2(2,4,6)+x3(0,1,1)=0. Because the first two columns are parallel, the equation reads (x1+2x2)(1,2,3)+x3(0,1,1)=0, and since those two vectors are independent both coefficients must vanish: x3=0 and x1=-2x2. So the null space is the line spanned by (-2,1,0), and indeed -2(1,2,3)+1(2,4,6)=0.

A whole line of inputs is sent to the origin, and a whole plane of outputs is reachable. One dimension was destroyed and two survived, which is the shape of the answer this lesson formalises.

Rank

The rank of A is the dimension of its column space, written r. It counts how many genuinely different directions the columns supply, which is how many independent directions survive the transformation. The example above has rank two.

Rank is found by elimination rather than by inspection. Row reducing A produces a staircase in which each step begins with a pivot, the first non-zero entry of its row, and the number of pivots is the rank. Columns carrying a pivot are called pivot columns and correspond to independent columns of the original matrix; the others are free columns, each of them a combination of the pivot columns to its left.

The nullity is the dimension of the null space. Each free column supplies exactly one basis vector of the null space, obtained by setting that free variable to one, all other free variables to zero, and solving back for the pivot variables. The example has one free column, the second, and correspondingly one null space basis vector.

That correspondence proves the central counting theorem, since every column is either a pivot column or a free one and no column is both:

rank+nullity=n

the number of columns. This is the rank-nullity theorem, and it is a conservation law: the input space has n dimensions, the map destroys the nullity of them and delivers the rank of them to the output, and the two numbers always add back to n. For the example, 2+1=3.

Example. Find the rank and nullity of B=[(1,1),(2,2),(3,3)], a two by three matrix.

Every column is a multiple of (1,1), so the column space is a line in R2 and the rank is 1. There are three columns, so the nullity is 3-1=2: a whole plane of inputs collapses to the origin. One check: 2(1,1)-1(2,2)=0 gives the null vector (2,-1,0), and 3(1,1)-1(3,3)=0 gives (3,0,-1), and those two are independent.

Now you. Find the rank and nullity of C=[(1,0),(0,1),(1,1)].

Answer

The first two columns already span R2, so the rank is 2 and the nullity is 3-2=1. The null vector satisfies x1(1,0)+x2(0,1)+x3(1,1)=0, giving x1=-x3 and x2=-x3, so the null space is spanned by (-1,-1,1).

The complete solution of a system

Now return to Ax=b with the tools assembled.

Existence. A solution exists exactly when b lies in the column space, since the column space is precisely the set of reachable vectors. For the example matrix, take b=(1,3,4), which is column one plus column three, so it is reachable and x=(1,0,1) is a solution. Now take b=(1,3,5). Reaching it needs a(1,2,3)+b(0,1,1)=(1,3,5), and the first component forces a=1, the second then forces b=1, and the third would need 3+1=5, which is false. That target is off the plane and no solution exists.

Uniqueness. If p is one solution and n is any null space vector, then A(p+n)=Ap+An=b+0=b, so p+n is also a solution. Conversely if p and q are both solutions then A(p-q)=0, so they differ by a null space vector. Hence the complete solution set is

{p+n:nN(A)}

one particular solution plus the whole null space. Geometrically it is a copy of the null space, shifted away from the origin by p. It is not a subspace unless b=0, since it misses the origin, which is why homogeneous systems are the well-behaved ones.

For the example with b=(1,3,4), the complete solution is (1,0,1)+t(-2,1,0) for any t. Checking at t=3: the input (-5,3,1) gives -5(1,2,3)+3(2,4,6)+1(0,1,1)=(-5+6,-10+12+1,-15+18+1)=(1,3,4), as promised.

Every statement of the first lesson now has a reason. No solution means b outside the column space. Exactly one means the null space is {0}, that is, nullity zero, that is, rank equal to the number of columns. Infinitely many means a non-trivial null space, and the solution set then has the dimension of that null space, so it is a line, a plane or larger, never a scattering of isolated points.

Example. With A as above, solve Ax=(2,5,7) completely.

Is it reachable? Solve a(1,2,3)+b(0,1,1)=(2,5,7): the first component gives a=2, the second 4+b=5 so b=1, and the third checks, 6+1=7. So p=(2,0,1) is one solution, using two of column one and one of column three. The complete solution is (2,0,1)+t(-2,1,0), a line of solutions.

Now you. A five by eight matrix has rank three. What is the dimension of its null space, and can Ax=b be solved for every b in R5?

Answer

Nullity is 8-3=5, by rank-nullity with n=8 columns. The column space has dimension three inside R5, so it is not all of R5 and most targets are unreachable. When a solution does exist it is never unique, since a five-dimensional family of null vectors can be added to it.

Tall, wide and square

The shape of a matrix bounds its rank, since the rank cannot exceed either the number of columns or the number of rows: the column space is spanned by n columns and lives inside Rm. So rmin(m,n), and a matrix achieving that bound is said to have full rank. Three cases are worth separating, because each is a different practical situation.

A tall matrix, with m>n, has more equations than unknowns. At best r=n, in which case the columns are independent, the null space is trivial and any solution is unique, but the column space is an n-dimensional sliver of Rm and almost every b misses it. Overdetermined systems are usually unsolvable and never have more than one solution. That is the case fitting a line to fifty data points produces.

A wide matrix, with m<n, has more unknowns than equations. At best r=m, in which case the column space is all of Rm and every b is reachable, but rank-nullity forces a null space of dimension n-m1, so solutions always come in infinite families. Underdetermined systems are usually solvable and never uniquely. A structure with more supports than the equilibrium equations can determine is in exactly this situation, and engineers call it statically indeterminate.

A square matrix of full rank r=n is the invertible case of the previous lesson, where existence and uniqueness both hold. It is the only shape that can manage both, and even then only when the rank is full.

Example. A 50 by 2 matrix has rank 2. What are the dimensions of its null space and column space, and what does that say about solving Ax=b?

The null space has dimension 2-2=0, so the only vector sent to the origin is 0 and a solution, if one exists, is unique. The column space has dimension 2 inside R50, a plane in a fifty-dimensional space, so a b assembled from measurements will not lie in it and no exact solution exists.

Now you. A 3 by 7 matrix has rank 3. Can Ax=b always be solved, and is the solution ever unique?

Answer

The column space has dimension 3 inside R3, so it is all of R3 and every b is reachable. But the nullity is 7-3=4, so every solution comes with a four-dimensional family of others. Always solvable, never uniquely.

Row rank equals column rank

The rows of A span a subspace of Rn called the row space, and its dimension is the row rank. There is no obvious reason for it to match the column rank, since the rows and columns of a rectangular matrix are different objects living in different spaces, and yet:

row rank=column rank

The reason is elimination. Row operations do not change the row space, since each new row is a combination of old ones and the process is reversible. Row operations also do not change which combinations of columns vanish, since each equation is transformed into an equivalent one, so they preserve the null space and therefore the column rank as well. In the reduced staircase form, both ranks are visibly the number of pivots. Counting pivots therefore counts both.

For the example matrix, the rows are (1,2,0), (2,4,1) and (3,6,1), and the third is the sum of the first two, so the row space is two-dimensional, matching the column rank of two.

One more consequence deserves stating, since it is where orthogonality enters. Every row of A, dotted with any null space vector x, gives zero, because that dot product is one component of Ax=0. So the null space is perpendicular to the row space. Check it: the null vector (-2,1,0) dotted with (1,2,0) gives -2+2=0, with (2,4,1) gives -4+4=0, and with (3,6,1) gives -6+6=0.

The two spaces have dimensions r and n-r and sit at right angles inside Rn, splitting the input space between them. The same argument applied to AT splits the output space Rm into the column space, of dimension r, and the null space of AT, of dimension m-r, which is what is left unreachable. For the example, m-r=1, and the unreachable direction is spanned by (1,1,-1): dotting it with each column gives 1+2-3=0, 2+4-6=0 and 0+1-1=0. Anything with a component along (1,1,-1) cannot be produced, which is precisely why (1,3,5) failed earlier.

These four subspaces, with dimensions r, n-r, r and m-r, are the full anatomy of a matrix.

Honest limits

Rank is exact in theory and delicate in practice. The matrix with columns (1,2,3), (2,4,6) and (0,1,1) has rank two, but change one entry from 4 to 4.000001 and the columns become independent, giving rank three. Real measurements always contain such perturbations, so a matrix built from data is almost always of full rank arithmetically while being close to a lower-rank one. Numerical software therefore reports the number of singular values above a tolerance, using the decomposition mentioned in the last lesson of this course, and calls that the rank. The honest statement is that rank near a threshold is a judgement, not a computation.

Second, the complete solution p+N(A) tells you the set but does not choose a member of it. When there are infinitely many solutions, applications need one, and the usual choice is the shortest, which is a projection problem. The tools for that are in the next lesson.

The awkward case is now the common one: b outside the column space, so no solution exists at all. Fifty measurements and two unknowns produce that situation nearly always, because fifty points do not lie on one line. Giving up is not the practice. The next lesson replaces the unreachable target by the closest reachable one, and finds that the whole method follows from a single right angle.

Orthogonality and least squares

Fifty measurements never lie exactly on one line, so the system that would fit a line to them has no solution, and the useful question becomes which line comes closest.

The previous lesson established that Ax=b is solvable exactly when b lies in the column space of A. When there are more equations than unknowns the column space is a small subspace of a large space, and a b built from measurements will miss it. This lesson replaces b by the nearest point of the column space, and the entire method comes from one geometric fact: the shortest route from a point to a subspace meets it at a right angle.

Projection onto a line, again

The lesson on vectors projected one vector onto another by requiring the leftover to be perpendicular. Given b and a direction a, the projection is ca where the condition a(b-ca)=0 forces

c=abaa

That single equation is the seed of everything below, and it is worth naming what it accomplishes: it finds the point of the line {ca} closest to b. Closest, because any other point ca on the line has b-ca2=b-ca2+(c-c)a2 by Pythagoras, the two pieces being perpendicular, and the second piece is positive unless c=c.

Example. Project b=(4,0,0) onto the line through a=(1,1,1).

ab=4 and aa=3, so c=4/3 and the projection is (1.3333,1.3333,1.3333). The error is (2.6667,-1.3333,-1.3333), whose dot product with (1,1,1) is 2.6667-1.3333-1.3333=0, confirming the right angle.

Now you. Project b=(0,0,6) onto the line through a=(1,2,2).

Answer

ab=12 and aa=9, so c=4/3=1.3333 and the projection is (1.3333,2.6667,2.6667). The error (-1.3333,-2.6667,3.3333) dotted with (1,2,2) gives -1.3333-5.3333+6.6667=0.

Projection onto a subspace, and the normal equations

Now replace the line by the column space of a matrix A. The problem is: find the vector p in C(A) closest to b. Since every element of the column space is Axˆ for some xˆ, the unknown is xˆ, and the error vector is e=b-Axˆ.

The condition is the same as before, generalised: the error must be perpendicular to the whole subspace, which means perpendicular to every column of A. Perpendicularity to each column is a dot product being zero, and the dot products of all the columns with e at once are the components of ATe. So the condition is

AT(b-Axˆ)=0

which rearranges into the normal equations:

ATAxˆ=ATb

This is a square system, of size n by n whatever the shape of A, and it is always consistent. When the columns of A are independent, ATA is invertible and the solution is unique. The projection is then p=Axˆ, and the quantity being minimised is b-Ax2, the sum of the squared errors, which is where the name least squares comes from.

Note what has happened. An unsolvable problem became a solvable one, of smaller size, by a change of question: not "which x satisfies the equations" but "which x misses by the least". The method was published by Legendre in 1805 and used by Gauss to recover the orbit of Ceres from a handful of observations in 1801, after the asteroid was lost behind the sun.

Fitting a straight line

Here is the whole machine on real numbers. A ball rolls along a track and its position is measured at four times: at t=0,1,2,3 seconds the readings are y=1,3,4,6 metres. Fit y=c+mt.

Demanding exactness gives four equations in two unknowns: c=1, c+m=3, c+2m=4, c+3m=6. In matrix form Ax=b with A=[(1,1,1,1),(0,1,2,3)], x=(c,m) and b=(1,3,4,6). The four points are not collinear, so no solution exists: b is a vector in R4 and the column space is only a plane.

Form the normal equations. ATA has first row ((1,1,1,1)(1,1,1,1),(1,1,1,1)(0,1,2,3))=(4,6) and second row (6,14), since 0+1+4+9=14. And ATb=((1,1,1,1)b,(0,1,2,3)b)=(14,29), since 0+3+8+18=29. So

4c+6m=146c+14m=29

The determinant is 56-36=20, so a solution exists and is unique: m=(4×29-6×14)/20=32/20=1.6 and c=(14-1.6×6)/4=4.4/4=1.1. The fitted line is y=1.1+1.6t, so the best estimate of the ball's speed is 1.6 m s⁻¹.

The fit can be audited. The predicted positions are 1.1, 2.7, 4.3 and 5.9, so the residuals are -0.1, +0.3, -0.3 and +0.1. Their sum is zero, which is the first normal equation, that the error is perpendicular to the column of ones. Their dot product with (0,1,2,3) is 0+0.3-0.6+0.3=0, which is the second. The sum of squares is 0.01+0.09+0.09+0.01=0.20, and no other line achieves a smaller value: that is what the perpendicularity guaranteed.

Example. Fit y=c+mt to the three points (1,2), (2,3) and (3,5).

The sums are t=6, y=10, t2=14 and ty=2+6+15=23. The normal equations are 3c+6m=10 and 6c+14m=23. Their determinant is 42-36=6, so m=(3×23-6×10)/6=9/6=1.5 and c=(10-9)/3=0.3333. The fitted values are 1.8333, 3.3333 and 4.8333, with residuals +0.1667, -0.3333 and +0.1667, summing to zero as required, and a squared error of 0.1667.

Now you. Fit a horizontal line y=c to the four readings 1,3,4,6. What is c, and what is it in ordinary language?

Answer

Now A is the single column (1,1,1,1), so the normal equation is 4c=14, giving c=3.5. Fitting a constant by least squares gives the arithmetic mean, which is what the mean is for: the number whose squared deviations from the data are smallest.

The projection matrix

Substituting xˆ=(ATA)-1ATb into p=Axˆ gives the projection as a matrix acting on b:

P=A(ATA)-1AT

Two properties identify it, and both can be read off the geometry rather than computed. P2=P, because projecting a point that is already in the subspace leaves it alone. And PT=P: projection matrices are symmetric, which follows from the formula since (ATA)-1 is symmetric and the outer factors transpose into each other. Symmetry is not obvious geometrically, and the final lesson explains why projections belong to the best-behaved family of matrices.

Two special cases check the formula. If A is square and invertible, its column space is everything, nothing needs projecting, and indeed P=A(A-1(AT)-1)AT=I. If A is a single column a, then ATA is the number aa and Pb=a(ab)/(aa), the line formula from the start of the lesson.

Orthonormal bases

Projection got complicated because the columns of A were not perpendicular. When they are, everything simplifies at once.

A set of vectors is orthonormal when each has length one and any two distinct ones are perpendicular. If q1,,qk are orthonormal then the coordinates of any vector in their span are simply dot products: writing v=c1q1++ckqk and dotting both sides with qi kills every term but one, leaving ci=vqi. No system needs solving.

Take q1=(0.6,0.8) and q2=(-0.8,0.6), which are unit vectors, since 0.36+0.64=1, and perpendicular, since -0.48+0.48=0. The coordinates of (2,3) in this basis are (2,3)(0.6,0.8)=1.2+2.4=3.6 and (2,3)(-0.8,0.6)=-1.6+1.8=0.2. Reconstructing: 3.6(0.6,0.8)+0.2(-0.8,0.6)=(2.16-0.16,2.88+0.12)=(2,3).

A square matrix Q whose columns are orthonormal is called an orthogonal matrix, and it satisfies QTQ=I, since the entry in row i and column j of QTQ is qiqj. So its inverse is its transpose, which costs nothing to compute. Such matrices preserve every length and every angle, because (Qu)(Qv)=uTQTQv=uv, and in the plane they are exactly the rotations, of determinant +1, and the reflections, of determinant -1. Their determinant is always ±1, since det(Q)2=det(QTQ)=1.

Any independent set can be turned into an orthonormal one by Gram-Schmidt: keep the first vector, normalised; from the second, subtract its projection onto the first and normalise what remains; from the third, subtract its projections onto both and normalise; and so on. Starting from (1,1,0) and (1,0,1): the first normalises to q1=(0.7071,0.7071,0). The second has a2q1=0.7071, so subtracting 0.7071q1=(0.5,0.5,0) leaves (0.5,-0.5,1), of length 1.5=1.2247, giving q2=(0.4082,-0.4082,0.8165). Their dot product is 0.2887-0.2887+0=0.

Example. Verify that Q=[(0.6,0.8),(-0.8,0.6)] is orthogonal, and find the coordinates of (5,0) in its columns.

Each column has length one and the two are perpendicular, as computed above, so QTQ=I. The coordinates are dot products: (5,0)(0.6,0.8)=3.0 and (5,0)(-0.8,0.6)=-4.0. Checking: 3(0.6,0.8)-4(-0.8,0.6)=(1.8+3.2,2.4-2.4)=(5,0). Note that 32+(-4)2=25=52, so the length is the same computed in either basis, which is what preserving length means.

Now you. What is the inverse of Q=[(0.6,0.8),(-0.8,0.6)], and what transformation is it?

Answer

The inverse is the transpose, QT=[(0.6,-0.8),(0.8,0.6)]. Since detQ=0.36+0.64=1, Q is a rotation, by the angle whose cosine is 0.6 and sine is 0.8, about 53.13°. Its inverse is the rotation by -53.13°, which is what the transpose describes.

Honest limits

The normal equations are the right derivation and the wrong algorithm. Forming ATA squares the condition number of A, the ratio of its largest stretching factor to its smallest, and squaring a condition number of 106 gives 1012, which exceeds what double precision can absorb. Numerical libraries fit by QR factorisation, in which A is written as an orthogonal matrix times a triangular one, or by the singular value decomposition, and they never form ATA. The geometry above is exactly right; the arithmetic route to it is not.

Least squares is also a choice, not a law. Squaring the residuals means one badly wrong measurement counts as much as many slightly wrong ones, so a single outlier can drag the whole line. It is the correct choice when errors are independent and normally distributed with equal variance, which Gauss proved and which is sometimes even true. When it is not, other measures of misfit are used, at the price of losing the linear algebra: minimising the sum of absolute errors has no formula like the normal equations.

Finally, a fitted line is a description of the data, not a licence to extrapolate. The ball's fitted position at t=0 is 1.1 metres while the measurement was 1.0, and nothing in the method says which is closer to the truth.

Coordinates in an orthonormal basis turned out to be free, which raises a question left open two lessons ago. If a basis can be chosen, what does a change of basis do to the matrix of a transformation, and how much can a good choice simplify it? That is the next lesson, and it leads directly to the last third of the course.

Change of basis

A matrix is not a transformation but a description of one, written in a particular basis, and choosing a better basis can make the same transformation far easier to read.

Two facts from earlier lessons are needed here. A basis gives every vector a unique list of coordinates, and the standard basis has been used silently everywhere so far. And the matrix of a transformation is the list of the images of the basis vectors, so it depends on which basis those are. This lesson makes the dependence explicit and turns it into a tool.

Coordinates in another basis

Take the basis b1=(1,1) and b2=(-1,1) of R2, which is independent and therefore a basis, since neither vector is a multiple of the other. The arrow with standard coordinates (3,1) has different coordinates here: solving a(1,1)+b(-1,1)=(3,1) gives a-b=3 and a+b=1, so a=2 and b=-1. The same arrow is (3,1) to one observer and (2,-1) to the other, and nothing about the arrow changed.

The translation between the two is a matrix. Let P=[(1,1),(-1,1)], whose columns are the new basis vectors written in standard coordinates. Then for any coordinate list c in the new basis, Pc is a combination of the new basis vectors with weights c, which is exactly the standard-coordinate version of the same arrow. So

vstandard=Pvnewvnew=P-1vstandard

and P is invertible precisely because its columns form a basis. It is worth pausing on the direction, which everyone gets backwards once: the matrix whose columns are the new basis vectors converts from new coordinates to standard ones.

Here detP=(1)(1)-(-1)(1)=2, so P-1=12[(1,-1),(1,1)] by the two by two formula. Applying it to (3,1) gives 12(3+1,-3+1)=(2,-1), matching the direct solution.

Example. Find the coordinates of (4,2) in the basis (1,1), (-1,1).

Apply P-1: 12(4+2,-4+2)=(3,-1). Checking, 3(1,1)-1(-1,1)=(3+1,3-1)=(4,2).

Now you. Find the coordinates of (0,6) in the same basis.

Answer

P-1(0,6)=12(0+6,0+6)=(3,3). Checking, 3(1,1)+3(-1,1)=(0,6). The arrow points straight up, and in a basis of two diagonal directions that takes equal amounts of each.

The matrix of a map in another basis

Now let A be the matrix of a transformation in the standard basis, and ask for its matrix B in the new one. The new matrix must do this: take new coordinates in, give new coordinates out.

There is no need to think geometrically about it. Break the job into three steps that are each already understood. Given new coordinates, first convert them to standard coordinates with P. Then apply A, which is the description that works in standard coordinates. Then convert the answer back to new coordinates with P-1. Since matrices compose right to left,

B=P-1AP

Two matrices related this way are called similar, and the relation says they are the same transformation seen by two observers using different rulers. Every geometric fact about the transformation is shared between them, and only the numbers differ.

Take A=[(2,1),(1,2)], whose action is not obvious by inspection: it sends (1,0) to (2,1) and (0,1) to (1,2), tilting both basis vectors inward. Compute B with the P above. First AP, whose columns are A applied to the columns of P: A(1,1)=1(2,1)+1(1,2)=(3,3), and A(-1,1)=-1(2,1)+1(1,2)=(-1,1). Then apply P-1 to each: P-1(3,3)=12(3+3,-3+3)=(3,0), and P-1(-1,1)=12(-1+1,1+1)=(0,1). So

B=[(3,0),(0,1)]

which is diagonal. In the new basis the transformation is trivial to describe: it triples everything along (1,1) and leaves everything along (-1,1) alone. That statement is a complete description of a map that looked like four unrelated numbers a moment ago, and it is checkable directly: A(1,1)=(3,3), three times (1,1), and A(-1,1)=(-1,1), unchanged.

The basis was not chosen at random, and how to find such a basis is the subject of the next lesson. The point here is what a good basis buys.

Example. Find the matrix of the reflection F=[(0,1),(1,0)], which swaps the axes, in the basis (1,1), (-1,1).

FP has columns F(1,1)=(1,1) and F(-1,1)=(1,-1). Applying P-1: P-1(1,1)=12(1+1,-1+1)=(1,0) and P-1(1,-1)=12(1-1,-1-1)=(0,-1). So B=[(1,0),(0,-1)], again diagonal. It says the reflection fixes the direction (1,1), which is the mirror line itself, and negates the direction (-1,1), which is perpendicular to the mirror. That is what a reflection does, stated in one line.

Now you. What is the matrix, in the standard basis, of the map that triples every vector along (1,1) and leaves every vector along (-1,1) alone?

Answer

That map is diagonal in the new basis, D=[(3,0),(0,1)], so in standard coordinates it is A=PDP-1, running the conversion the other way. Computing: DP-1=12[(3,-1),(3,1)], and multiplying by P on the left gives columns 12[3(1,1)-1(-1,1)]=12(4,2)=(2,1) and 12[3(1,1)+1(-1,1)]=12(2,4)=(1,2). So A=[(2,1),(1,2)], which is where the section started.

Building a transformation the easy way

That last exercise is a method, and it is how awkward transformations are constructed in practice: describe the map in the basis where it is obvious, then conjugate back.

Find the matrix that reflects the plane in the line through (2,1). Doing this directly requires trigonometry. Doing it by change of basis requires none. Take b1=(2,1) along the mirror line and b2=(-1,2) perpendicular to it, since (2)(-1)+(1)(2)=0. In that basis the reflection fixes the first direction and negates the second, so its matrix is D=[(1,0),(0,-1)].

Now convert. P=[(2,1),(-1,2)] with detP=4+1=5, so P-1=15[(2,-1),(1,2)]. Then DP-1=15[(2,1),(1,-2)], negating the second component of each column, and multiplying on the left by P gives columns 15[2(2,1)+1(-1,2)]=15(3,4) and 15[1(2,1)-2(-1,2)]=15(4,-3). So

A=[(0.6,0.8),(0.8,-0.6)]

Check it against the formula derived in the lesson on transformations, [(cos2θ,sin2θ),(sin2θ,-cos2θ)] for a mirror at angle θ. Here tanθ=1/2, and the double angle identities give cos2θ=(1-tan2θ)/(1+tan2θ)=0.75/1.25=0.6 and sin2θ=2tanθ/(1+tan2θ)=1/1.25=0.8. The two routes agree exactly. Direct verification is easier still: A(2,1)=2(0.6,0.8)+1(0.8,-0.6)=(2,1), the mirror line fixed, and A(-1,2)=-1(0.6,0.8)+2(0.8,-0.6)=(1,-2), the perpendicular reversed.

Between two bases, neither of them standard

The standard basis has played the role of a hub so far: every conversion went through it. Nothing requires that, and the general case is a composition of two conversions already understood.

Let U and V be two bases, with PU and PV the matrices whose columns are their vectors in standard coordinates. To convert U coordinates into V coordinates, first go up to standard coordinates with PU, then down into V coordinates with PV-1. So the conversion matrix is PV-1PU, and the same three-step reading gives the matrix of a transformation in V from its matrix in U, by conjugating with it.

Take U={(1,1),(-1,1)} and V={(2,1),(-1,2)}, both bases since neither pair is parallel. Then PV=[(2,1),(-1,2)] has determinant 5, so PV-1=15[(2,-1),(1,2)], and the conversion matrix has columns PV-1(1,1)=15(3,1)=(0.6,0.2) and PV-1(-1,1)=15(-1,3)=(-0.2,0.6).

Test it. The arrow with U coordinates (2,-1) is 2(1,1)-1(-1,1)=(3,1) in standard coordinates. Applying the conversion matrix to (2,-1) gives 2(0.6,0.2)-1(-0.2,0.6)=(1.4,-0.2), and checking in V: 1.4(2,1)-0.2(-1,2)=(2.8+0.2,1.4-0.4)=(3,1). The same arrow, described three ways.

Example. Using the conversion matrix above, what are the V coordinates of the arrow whose U coordinates are (1,1)?

Apply it: 1(0.6,0.2)+1(-0.2,0.6)=(0.4,0.8). Checking, the arrow is 1(1,1)+1(-1,1)=(0,2) in standard coordinates, and 0.4(2,1)+0.8(-1,2)=(0.8-0.8,0.4+1.6)=(0,2).

Now you. Which matrix converts V coordinates back into U coordinates?

Answer

The inverse of the one above, which is PU-1PV by the same argument run the other way. Since det[(0.6,0.2),(-0.2,0.6)]=0.36+0.04=0.4, the inverse is 10.4[(0.6,-0.2),(0.2,0.6)]=[(1.5,-0.5),(0.5,1.5)]. Applying it to (1.4,-0.2) gives 1.4(1.5,-0.5)-0.2(0.5,1.5)=(2.1-0.1,-0.7-0.3)=(2,-1), the U coordinates it started from.

What survives a change of basis

Similar matrices describe the same map, so any quantity with a genuine geometric meaning must be the same for both. Two are easy to establish.

The determinant survives: det(P-1AP)=det(P-1)det(A)det(P)=det(A), using the multiplication rule and det(P-1)=1/det(P). This had to happen, since the determinant is a ratio of areas and a ratio does not care what units the areas are measured in. Above, detA=4-1=3 and detB=3×1=3.

The trace, the sum of the diagonal entries, also survives. It follows from the fact that tr(XY)=tr(YX) for any two matrices, which is a short computation with the entry formula, since both sides sum xijyji over all i and j. Then tr(P-1AP)=tr(APP-1)=tr(A). Above, trA=2+2=4 and trB=3+1=4. Unlike the determinant, the trace has no obvious geometric reading yet; the next lesson supplies one.

Rank survives too, being the dimension of the image, and so does invertibility. What does not survive is anything to do with the entries themselves: whether a matrix is diagonal, whether it is symmetric, how large its entries are. Those are properties of a description.

Example. Are [(2,1),(1,2)] and [(3,0),(0,2)] similar?

Compare invariants. The traces are 4 and 5, which already differ, so no similarity is possible. There is no need to search for a P.

Now you. Are [(1,0),(1,1)] and [(1,0),(0,1)] similar? Both have trace 2 and determinant 1.

Answer

No. The second is the identity, and P-1IP=P-1P=I for every invertible P, so the only matrix similar to the identity is the identity itself. The first is a shear, which is not the identity. Matching invariants are necessary for similarity, not sufficient.

Honest limits

A change of basis requires P to be invertible, so its columns must be a basis. Nothing else is required of them: they need not be perpendicular and need not have length one. When they are orthonormal, P-1=PT and the conversion is free, which is the practical reason orthonormal bases are worth building.

Numerically, a nearly dependent basis makes P badly conditioned, and errors in the entries of A are amplified by roughly the condition number of P when P-1AP is formed. Two matrices can therefore be similar in exact arithmetic and behave very differently in floating point, which is why numerical algorithms restrict themselves to orthogonal P wherever they can.

The important limit is the one this lesson has been circling. Twice now a well-chosen basis turned a matrix diagonal, which reduced a transformation to a list of stretch factors along a list of directions. Nothing so far says which matrices allow this, how to find the directions, or whether they exist at all. Since a diagonal matrix in the new basis means each new basis vector is simply scaled by the map, the directions being sought are the ones the transformation leaves on their own line. Those are the eigenvectors, and finding them is the next lesson.

Eigenvectors and eigenvalues

A basis in which a matrix becomes diagonal must be made of vectors that the transformation merely stretches, and those vectors can be found by solving one polynomial equation.

The previous lesson showed what a change of basis does, and twice produced a diagonal matrix from a basis chosen without explanation. A diagonal matrix in a basis b1,b2, says exactly that each bi is sent to a multiple of itself, since column i of the new matrix is the image of bi in the new coordinates, and having only the ith entry non-zero means the image is a multiple of bi. So the search is for directions the map does not turn.

The definition

A non-zero vector v is an eigenvector of a square matrix A when

Av=λv

for some scalar λ, called the corresponding eigenvalue. The transformation may stretch v, shrink it, or reverse it, but it leaves it on the line through the origin that it started on.

The requirement that v be non-zero is not pedantry: A0=λ0 holds for every λ and would make the definition empty. Eigenvalues, by contrast, may perfectly well be zero, and λ=0 means Av=0 for a non-zero v, which says the null space is non-trivial and the matrix is singular. So a matrix is invertible exactly when zero is not one of its eigenvalues, which is the determinant criterion in a new dress.

Note also that eigenvectors come in lines, not as individual arrows: if v works then so does cv for any non-zero c, with the same eigenvalue, since A(cv)=cAv=cλv=λ(cv). Quoting an eigenvector always means quoting one representative of a whole line.

Some are visible without any computation. For the projection [(1,0),(0,0)], the vector (1,0) is fixed, so it is an eigenvector with eigenvalue 1, and (0,1) is sent to 0, so it is an eigenvector with eigenvalue 0. For a reflection, everything along the mirror has eigenvalue 1 and everything perpendicular to it has eigenvalue -1. For a scaling by c, every vector is an eigenvector with eigenvalue c.

Finding them

Rewrite the definition as Av-λv=0, and insert the identity so that both terms are matrices acting on v:

(A-λI)v=0

This says v is in the null space of A-λI. A non-zero vector is there only if that matrix is singular, and the test for singularity is the determinant. So the eigenvalues are exactly the solutions of the characteristic equation

det(A-λI)=0

and once a λ is known, its eigenvectors are found by solving the singular system (A-λI)v=0, whose solutions form a subspace called the eigenspace of λ.

For a two by two matrix the equation takes a memorable form. With A=[(a,c),(b,d)], the matrix A-λI is [(a-λ,c),(b,d-λ)], whose determinant is (a-λ)(d-λ)-bc=λ2-(a+d)λ+(ad-bc). So

λ2-(traceA)λ+detA=0

which is why the trace was worth naming in the previous lesson. Comparing coefficients with (λ-λ1)(λ-λ2) gives two facts that hold in every dimension: the eigenvalues sum to the trace and multiply to the determinant. Both are free checks on any computation, and both explain why trace and determinant survive a change of basis, since eigenvalues plainly do.

Example. Find the eigenvalues and eigenvectors of A=[(4,1),(-2,1)].

The trace is 4+1=5 and the determinant is (4)(1)-(-2)(1)=6, so the characteristic equation is λ2-5λ+6=0, factoring as (λ-2)(λ-3)=0. The eigenvalues are 2 and 3, which sum to 5 and multiply to 6 as required.

For λ=2, solve (A-2I)v=0. That matrix is [(2,1),(-2,-1)], whose rows are (2,-2) and (1,-1), so both equations say v1=v2 and the eigenvector is (1,1). Check: A(1,1)=1(4,1)+1(-2,1)=(2,2)=2(1,1).

For λ=3, the matrix is [(1,1),(-2,-2)], with rows (1,-2) and (1,-2), so v1=2v2 and the eigenvector is (2,1). Check: A(2,1)=2(4,1)+1(-2,1)=(6,3)=3(2,1).

Now you. Find the eigenvalues and eigenvectors of B=[(1,2),(2,1)].

Answer

The trace is 2 and the determinant is 1-4=-3, so λ2-2λ-3=0, that is (λ-3)(λ+1)=0, giving λ=3 and λ=-1. For λ=3, the matrix B-3I has rows (-2,2) and (2,-2), so v1=v2 and the eigenvector is (1,1); check B(1,1)=(3,3). For λ=-1, the rows are (2,2) and (2,2), so v1=-v2 and the eigenvector is (1,-1); check B(1,-1)=1(1,2)-1(2,1)=(-1,1)=-1(1,-1). The negative eigenvalue means that direction is reversed as well as kept.

Reading the numbers

An eigenvalue is a stretch factor along its own direction, and its size and sign say what happens there. A value greater than one stretches, between zero and one shrinks, negative reverses, and exactly one leaves the direction fixed pointwise. Zero collapses it.

That reading makes repeated application easy, which is the main practical use of the whole idea. Since A2v=A(λv)=λ2v and so on, Akv=λkv: along an eigenvector, applying the matrix a thousand times is one exponentiation. Whichever eigenvalue is largest in absolute value comes to dominate, since its power grows fastest, so the long-run behaviour of a repeated linear process is governed by the largest eigenvalue and its direction. The next lesson makes that quantitative.

Two more consequences are worth having. If A is invertible and Av=λv, then applying A-1 to both sides gives A-1v=(1/λ)v: the inverse has the same eigenvectors with reciprocal eigenvalues. And (A+cI)v=(λ+c)v, so adding a multiple of the identity shifts every eigenvalue by c and moves no eigenvector, a trick used constantly in numerical work.

A triangular matrix gives its eigenvalues away, since det(A-λI) for a triangular matrix is the product of its diagonal entries minus λ. The matrix with columns (2,0,0), (1,3,0) and (4,5,7) has eigenvalues 2, 3 and 7, read straight off the diagonal, and that is one reason elimination-based algorithms aim at triangular forms.

Example. The matrix A=[(2,1),(1,2)] has eigenvalues 3 and 1 with eigenvectors (1,1) and (-1,1). What is A10(1,1), and what does A do to (2,1) in the long run?

A10(1,1)=310(1,1)=59049(1,1). For (2,1), write it in the eigenvector basis: (2,1)=1.5(1,1)-0.5(-1,1), since 1.5+0.5=2 and 1.5-0.5=1. Then Ak(2,1)=1.5×3k(1,1)-0.5×1k(-1,1). The first term grows without bound and the second stays fixed, so the direction of Ak(2,1) converges to (1,1), and after ten steps the two terms are 88573.5(1,1) against 0.5(-1,1), so the deviation is already invisible.

Now you. For the same A, what are the eigenvalues of A-1 and of A+2I?

Answer

A-1 has eigenvalues 1/3 and 1, with the same eigenvectors. A+2I has eigenvalues 5 and 3, again with the same eigenvectors. As a check, A+2I=[(4,1),(1,4)] has trace 8=5+3 and determinant 16-1=15=5×3.

A three by three, and what its eigenvectors mean

Larger matrices work the same way, with a cubic to solve instead of a quadratic. Take the matrix with columns (2,-1,0), (-1,2,-1) and (0,-1,2), which is symmetric and arises from three equal masses in a line, each joined by identical springs to its neighbours and the outer two to fixed walls.

Expanding det(A-λI) along the first row, with μ=2-λ for brevity, gives μ(μ2-1)-(-1)(-μ)=μ3-2μ, which factors as μ(μ2-2). So μ=0 or μ=±2, and the eigenvalues are

λ=2,λ=2-2=0.5858,λ=2+2=3.4142

They sum to 6, matching the trace, and multiply to 2(4-2)=4, matching the determinant, which expands directly to 2(4-1)-(-1)(-2)=4.

Each eigenvector is found by solving (A-λI)v=0. For λ=2 the first equation is -v2=0 and the second is -v1-v3=0, giving v=(1,0,-1): the middle mass stays still while the outer two move oppositely. For λ=2-2 the equations give v2=2v1 and v1=v3, so v=(1,1.4142,1): all three move the same way with the middle one furthest. For λ=2+2 the sign flips, giving v=(1,-1.4142,1), with the middle mass opposing its neighbours. Checking the last: A(1,-1.4142,1)=(2+1.4142,-1-2.8284-1,1.4142+2)=(3.4142,-4.8284,3.4142), which is 3.4142 times (1,-1.4142,1).

Those three patterns are the normal modes of the system: the shapes in which it can oscillate without changing shape, each at its own frequency, proportional to the square root of its eigenvalue. Any motion whatever is a combination of the three, which is why eigenvectors are how vibration is analysed, in a violin string, a bridge deck or a molecule. The highest mode here has 3.4142/0.5858=2.414 times the frequency of the lowest.

When it fails

Two failures are guaranteed to be met, and pretending otherwise makes the next lesson impossible to understand.

A rotation has no real eigenvectors. Take the quarter turn R=[(0,1),(-1,0)]. Its trace is 0 and its determinant is 1, so the characteristic equation is λ2+1=0, which has no real solution. The geometry says the same thing more plainly: a quarter turn moves every direction, so no line survives. For a rotation by θ the equation is λ2-2cosθλ+1=0, whose discriminant 4cos2θ-4 is negative unless θ is a multiple of 180°.

Allowing complex numbers rescues the algebra: the roots are cosθ±isinθ, of modulus one, which is the algebra reporting that a rotation preserves length while turning by θ. Complex eigenvalues of a real matrix always arrive in conjugate pairs, and a pair with non-zero imaginary part always signals rotation of some kind. This course keeps to real numbers, so a rotation is simply a matrix with no eigenvectors here, and the complex theory is the standard next step.

A shear has too few. Take S=[(1,0),(1,1)], with trace 2 and determinant 1, so the equation is λ2-2λ+1=(λ-1)2=0 and λ=1 is a repeated root. Solving (S-I)v=0: the matrix S-I has columns (0,0) and (1,0), so its rows are (0,1) and (0,0), and the condition is v2=0. The eigenspace is only the line through (1,0), one dimension, though the eigenvalue was repeated twice. Geometrically, the horizontal axis is fixed and every other direction is tilted, so there is nowhere else to look.

A matrix like this, whose eigenvectors do not supply a full basis, is called defective, and no change of basis makes it diagonal. That the failure is possible is exactly what makes the next lesson's theorem worth having.

Example. How many independent eigenvectors does the rotation by 60° have in the real plane, and how many does [(1,0),(0,1)] have?

The rotation has none: its characteristic equation is λ2-λ+1=0, with discriminant 1-4=-3<0, since 2cos60°=1. The identity has an eigenvalue 1 repeated twice, and every non-zero vector is an eigenvector, so it has two independent ones and is already diagonal. A repeated eigenvalue therefore does not by itself imply trouble.

Now you. The matrix [(5,0),(0,5)] and the matrix [(5,0),(1,5)] both have λ=5 twice. How many independent eigenvectors does each have?

Answer

The first is 5I, which scales everything, so every vector is an eigenvector and there are two independent ones. For the second, A-5I has columns (0,0) and (1,0), so the condition is v2=0 and only the line through (1,0) qualifies: one independent eigenvector, and the matrix is defective. Two matrices with identical characteristic equations can behave completely differently.

Honest limits

The characteristic polynomial is the right definition and a poor algorithm. Abel proved in 1824 that polynomials of degree five and above have no general solution in radicals, so for a five by five matrix there is no formula for the eigenvalues, and none can exist. Every practical eigenvalue computation is therefore iterative, and the standard method, the QR algorithm from about 1961, repeatedly factorises the matrix into an orthogonal part and a triangular part and reassembles them in the other order, which drives the matrix towards triangular form and reads the eigenvalues off the diagonal. Forming the characteristic polynomial explicitly is also numerically disastrous, since polynomial roots can be wildly sensitive to their coefficients.

Eigenvalues can also be badly conditioned in their own right: for a defective or nearly defective matrix, a perturbation of size ε in the entries can move the eigenvalues by about ε, so a change in the twelfth digit shifts the answer in the sixth. Symmetric matrices are free of this problem, which is one more reason the final lesson gives them a section to themselves.

When the eigenvectors do form a basis, the change of basis of the previous lesson turns the matrix diagonal, and everything about repeated application becomes arithmetic on a handful of numbers. That is the next lesson.

Diagonalisation and powers

Applying a matrix a thousand times is a thousand matrix multiplications in general and a single exponentiation along an eigenvector, so a basis of eigenvectors converts the hard problem into the easy one.

The previous two lessons supply everything needed. A change of basis replaces A by P-1AP, where the columns of P are the new basis vectors. An eigenvector is a direction the transformation merely scales. Putting the two together is this lesson.

The factorisation

Suppose an n by n matrix A has n independent eigenvectors v1,,vn, with eigenvalues λ1,,λn. Let P be the matrix whose columns are those eigenvectors, and D the diagonal matrix with the eigenvalues down the diagonal in the same order.

Consider AP. Its jth column is A applied to the jth column of P, which is Avj=λjvj. Now consider PD. Its jth column is P applied to the jth column of D, which is λj times the jth standard basis vector, so P applied to it is λjvj. The two agree column by column, so

AP=PDhenceA=PDP-1andD=P-1AP

where P is invertible precisely because the eigenvectors were assumed independent. A matrix admitting this is called diagonalisable, and D is its description in the eigenvector basis: a list of stretch factors, one per direction.

Take A=[(4,1),(-2,1)], whose eigenvalues were found to be 2 and 3 with eigenvectors (1,1) and (2,1). Then P=[(1,1),(2,1)] and D=[(2,0),(0,3)]. Since detP=(1)(1)-(2)(1)=-1, the inverse is P-1=[(-1,1),(2,-1)], and multiplying out PDP-1 returns [(4,1),(-2,1)] exactly.

Example. Diagonalise B=[(1,2),(2,1)].

Its eigenvalues are 3 and -1, with eigenvectors (1,1) and (1,-1), from the previous lesson. So P=[(1,1),(1,-1)] and D=[(3,0),(0,-1)]. Here detP=-1-1=-2, so P-1=12[(1,1),(1,-1)], which happens to be 12P because the eigenvectors are perpendicular and of equal length. Multiplying PDP-1 reproduces B.

Now you. Diagonalise C=[(2,1),(1,2)], whose eigenvalues are 3 and 1.

Answer

The eigenvectors are (1,1) for λ=3 and (-1,1) for λ=1, so P=[(1,1),(-1,1)] and D=[(3,0),(0,1)]. This is the change of basis performed two lessons ago, now explained: the basis that worked was the eigenvector basis, and there was never anything else it could have been.

Powers become arithmetic

The point of the factorisation is what it does to repeated application. Since

A2=(PDP-1)(PDP-1)=PD(P-1P)DP-1=PD2P-1

and the same collapse happens at every stage, Ak=PDkP-1 for every k. Raising a diagonal matrix to a power raises each diagonal entry to that power and nothing else, so the entire cost is n exponentiations plus two matrix multiplications, however large k is.

Do it explicitly for C=[(2,1),(1,2)], with P=[(1,1),(-1,1)], D=[(3,0),(0,1)] and P-1=12[(1,-1),(1,1)]. Multiplying out gives every entry as a combination of 3k and 1k:

Ck=12[(3k+1,3k-1),(3k-1,3k+1)]

At k=1 that is [(2,1),(1,2)], correct. At k=3 it gives [(14,13),(13,14)], and multiplying C by itself three times confirms it. At k=5 it gives [(122,121),(121,122)], which also checks. The general behaviour is now readable: every entry grows like 3k/2, so the matrix is asymptotically 123k times the matrix of all ones, and the dominant eigenvalue dictates everything.

Example. Using the formula above, what is C10?

310=59049, so the diagonal entries are (59049+1)/2=29525 and the off-diagonal entries are (59049-1)/2=29524. Ten matrix multiplications avoided, and the answer is exact.

Now you. What is C4?

Answer

34=81, so C4=[(41,40),(40,41)]. Checking against C3=[(14,13),(13,14)]: multiplying by C gives first column 14(2,1)+13(1,2)=(28+13,14+26)=(41,40), which agrees.

A Markov chain

Here is the machinery on a problem worth solving. Two mobile networks compete. Each month, 10 per cent of network A's customers leave for B, and 20 per cent of B's leave for A. Writing the state as the pair of market shares, the update is xk+1=Mxk with

M=[(0.9,0.1),(0.2,0.8)]

whose first column says where A's customers go and whose second says where B's go. Each column sums to one, since customers are not created or destroyed, which is what makes this a Markov matrix.

Find the eigenvalues. The trace is 1.7 and the determinant is 0.72-0.02=0.70, so λ2-1.7λ+0.7=0, which factors as (λ-1)(λ-0.7)=0. The eigenvalue 1 is not a coincidence. Every column of M-I sums to zero, so adding all the rows of M-I together gives a row of zeros, which makes the rows dependent and the matrix singular. Hence det(M-I)=0, and λ=1 is an eigenvalue of every Markov matrix.

The eigenvector for λ=1 solves (M-I)v=0, where M-I=[(-0.1,0.1),(0.2,-0.2)] has rows (-0.1,0.2) and (0.1,-0.2), so v1=2v2 and the eigenvector is (2,1), or as shares, (2/3,1/3). For λ=0.7, the matrix M-0.7I=[(0.2,0.1),(0.2,0.1)] has rows (0.2,0.2) and (0.1,0.1), so v1=-v2 and the eigenvector is (1,-1).

Now start with everyone on network A, x0=(1,0), and write it in the eigenvector basis: a(2,1)+b(1,-1)=(1,0) gives a=b=1/3. Then

xk=13(2,1)+13(0.7)k(1,-1)

because each eigenvector component is multiplied by its own eigenvalue each month. The first term never changes. The second decays by a factor 0.7 per month, so the shares converge to (2/3,1/3)=(66.7%,33.3%) whatever the starting point, and the speed of the approach is set by the second eigenvalue.

Check at k=5: 0.75=0.16807, so the formula gives (0.6667+0.0560,0.3333-0.0560)=(0.7227,0.2773). Multiplying by M five times directly gives (0.9,0.1), then (0.83,0.17), (0.781,0.219), (0.7467,0.2533) and finally (0.72269,0.27731). The two agree to every digit shown.

This is the whole method of eigenvalue analysis of a repeated process, and it reads off three things that simulation gives only slowly: the limit, the fact that the limit is independent of the start, and the rate of approach.

Example. For M=[(0.8,0.2),(0.3,0.7)], find the long-run shares.

Trace 1.5, determinant 0.56-0.06=0.50, so λ2-1.5λ+0.5=0 and the eigenvalues are 1 and 0.5. For λ=1: M-I=[(-0.2,0.2),(0.3,-0.3)], whose first row is (-0.2,0.3), so 0.2v1=0.3v2 and v=(3,2). As shares that is (0.6,0.4), and checking, M(0.6,0.4)=0.6(0.8,0.2)+0.4(0.3,0.7)=(0.48+0.12,0.12+0.28)=(0.6,0.4), fixed as it should be. The deviation halves each step, since the second eigenvalue is 0.5.

Now you. In the original chain, how many months until the deviation from the steady state falls below one per cent of its initial size?

Answer

The deviation is multiplied by 0.7 each month, so it needs 0.7k<0.01, that is k>ln(0.01)/ln(0.7)=(-4.605)/(-0.3567)=12.9. So thirteen months. Note that the answer depends only on the second eigenvalue and not at all on the starting shares.

Fibonacci in closed form

The same trick produces a formula for a sequence defined by a rule. The Fibonacci numbers satisfy Fk+1=Fk+Fk-1 with F0=0 and F1=1. Package two consecutive terms as a vector: if uk=(Fk+1,Fk) then uk+1=Auk with A=[(1,1),(1,0)], since the new pair is (Fk+1+Fk,Fk+1).

The trace is 1 and the determinant is -1, so λ2-λ-1=0 and the eigenvalues are

λ=1±52

that is φ=1.618034, the golden ratio, and ψ=-0.618034. Diagonalising and reading off the second component gives Binet's formula,

Fn=φn-ψn5

Test it at n=10: φ10=122.9919 and ψ10=0.008131, so F10=122.9837/2.23607=55.000, which is correct. Since |ψ|<1 its powers vanish, so Fn is the nearest whole number to φn/5, and consecutive Fibonacci numbers have ratio tending to φ. A formula built entirely out of irrational numbers returns whole numbers every time, which is the two irrational parts cancelling exactly.

When it fails, and one guarantee

Not every matrix is diagonalisable. The shear [(1,0),(1,1)] has only one independent eigenvector, so no basis of eigenvectors exists and no P can be built. Since similarity preserves the eigenvalues, and a diagonal matrix similar to it would have to be I, and the only matrix similar to I is I itself, the shear is provably not diagonalisable rather than merely resistant.

One condition is easy to check and covers most cases: if the n eigenvalues are distinct, the matrix is diagonalisable. The reason is that eigenvectors with different eigenvalues are automatically independent. Suppose v1 and v2 have distinct eigenvalues and c1v1+c2v2=0. Apply A to get c1λ1v1+c2λ2v2=0, and subtract λ2 times the first relation to get c1(λ1-λ2)v1=0. Since λ1λ2 and v10, we get c1=0, and then c2=0 too. The same argument extended by induction handles n eigenvectors.

Distinct eigenvalues are sufficient and not necessary: the identity has every eigenvalue equal and is already diagonal. The genuine criterion is that each repeated eigenvalue must supply as many independent eigenvectors as its multiplicity in the characteristic polynomial, and a defective matrix is one where it does not.

Honest limits

Diagonalisation over the real numbers fails for rotations, which have no real eigenvectors at all, and over the complex numbers it fails for defective matrices such as the shear. The complete answer is the Jordan form, in which any matrix is similar to a nearly diagonal one with the eigenvalues on the diagonal and some ones just above it, one for each missing eigenvector. It is a theoretical instrument only: the Jordan form is discontinuous in the entries, so any rounding destroys it, and no numerical library computes it.

The factorisation is also useless when P is badly conditioned, meaning the eigenvectors are nearly parallel. Then P-1 has enormous entries, and the near-cancellation that follows swamps the answer. The tell is that a matrix close to a defective one has eigenvectors close to parallel, so being nearly defective is the practical version of being defective.

Finally, this whole method requires the same matrix to be applied repeatedly. A process whose matrix changes at every step gets no benefit, since A2A1 has no relation to the eigenvectors of either factor.

One family of matrices escapes every one of these problems. Symmetric matrices always have a full set of eigenvectors, always have real eigenvalues, and their eigenvectors are always perpendicular, which makes P orthogonal and P-1 free. That is the last lesson, together with what such matrices are for.

Symmetric matrices and quadratic forms

Every difficulty in the previous lesson, missing eigenvectors, complex eigenvalues and ill-conditioned changes of basis, disappears for matrices equal to their own transpose.

A matrix is symmetric when A=AT, which for a two by two means the off-diagonal entries are equal: [(a,b),(b,d)]. The definition looks like a coincidence of notation. It is not, and this lesson proves what symmetry guarantees, shows what such matrices compute, and explains why they dominate applied work.

Two proofs

Eigenvectors of distinct eigenvalues are perpendicular. Suppose Au=λu and Av=μv with λμ. Compute u(Av) in two ways. Directly, it is u(μv)=μ(uv). But writing the dot product as a matrix product, uTAv=(ATu)Tv=(Au)Tv, using symmetry to replace AT by A, and that is λ(uv). So λ(uv)=μ(uv), and since λμ the dot product must be zero.

Three lines, and the geometric content is large: the axes of a symmetric transformation meet at right angles.

The eigenvalues are real. For a general real matrix they need not be, as the rotation showed. Suppose Av=λv with λ and v possibly complex, and let v be the entrywise complex conjugate. The quantity vTAv equals λvTv, and vTv is the sum of |vi|2, a positive real number. Conjugating and transposing the whole expression, and using that A is real and symmetric, returns the same quantity with λ replaced by λ. So λ=λ, which for a complex number means it is real.

Together with a slightly harder argument that covers repeated eigenvalues, these give the spectral theorem: every real symmetric matrix has a full set of real eigenvalues and an orthonormal basis of eigenvectors, so

A=QDQT

with Q orthogonal and D diagonal and real. The inverse of Q is its transpose, so the change of basis costs nothing and is perfectly conditioned. Symmetric matrices are never defective, never need complex numbers, and never produce a badly conditioned P: all three failure modes of the previous lesson are excluded at once.

Example. Diagonalise A=[(5,2),(2,2)] and confirm that its eigenvectors are perpendicular.

The trace is 7 and the determinant is 10-4=6, so λ2-7λ+6=0 and the eigenvalues are 6 and 1, both real. For λ=6, the first row of A-6I is (-1,2), so v1=2v2 and the eigenvector is (2,1). For λ=1, the first row of A-I is (4,2), so 2v1=-v2 and the eigenvector is (1,-2). Their dot product is 2-2=0. Normalising, Q=[(0.8944,0.4472),(0.4472,-0.8944)] and D=[(6,0),(0,1)].

Now you. Diagonalise B=[(3,1),(1,3)].

Answer

Trace 6, determinant 9-1=8, so λ2-6λ+8=0 and the eigenvalues are 4 and 2. For λ=4 the first row of B-4I is (-1,1), giving the eigenvector (1,1); for λ=2 it is (1,1), giving (1,-1). Their dot product is zero. Normalised, the two are (0.7071,0.7071) and (0.7071,-0.7071).

Quadratic forms

Symmetric matrices exist to compute quadratic expressions. Given a symmetric A, the function

q(x)=xTAx

is a quadratic form: every term is of degree two. For a two by two A=[(a,b),(b,d)], expanding gives q(x,y)=ax2+2bxy+dy2. So 5x2+4xy+2y2 corresponds to a=5, 2b=4 and d=2, which is the matrix [(5,2),(2,2)] diagonalised above. Note that the cross term is split evenly between the two off-diagonal entries, which is exactly why the matrix can be taken symmetric with no loss.

Now apply the spectral theorem. In the eigenvector basis the matrix is diagonal, so the form becomes a plain sum of squares with the eigenvalues as coefficients: if u and v are the coordinates along the two orthonormal eigenvectors, then

q=λ1u2+λ2v2

with no cross term at all. For the example, q=6u2+v2 where u is measured along (2,1)/5 and v along (1,-2)/5. The cross term 4xy was an artefact of using coordinates misaligned with the natural axes of the form.

That makes the level curves readable. The set q=1 is 6u2+v2=1, an ellipse with semi-axis 1/6=0.4082 in the u direction and 1 in the v direction: the larger the eigenvalue, the shorter the axis, since a steeper form reaches the value 1 sooner. Checking one point directly, 0.4082 along (2,1)/5 is (0.3651,0.1826), and 5(0.3651)2+4(0.3651)(0.1826)+2(0.1826)2=0.6667+0.2667+0.0667=1.0000, on the curve as predicted.

Example. Sketch the curve 3x2+2xy+3y2=1 by finding its axes.

The matrix is [(3,1),(1,3)], diagonalised above with eigenvalues 4 and 2 and eigenvectors (1,1) and (1,-1). So the curve is 4u2+2v2=1, an ellipse with semi-axis 1/2=0.5 along (1,1)/2 and 1/2=0.7071 along (1,-1)/2. Check the first: the point 0.5(1,1)/2=(0.3536,0.3536) gives 3(0.125)+2(0.125)+3(0.125)=1.000.

Now you. What shape is the curve x2+4xy+y2=1?

Answer

The matrix is [(1,2),(2,1)], whose eigenvalues are 3 and -1 with eigenvectors (1,1) and (1,-1). The form is 3u2-v2, and with one positive and one negative coefficient the curve 3u2-v2=1 is a hyperbola, not an ellipse. Signs of the eigenvalues decide the shape.

Definiteness

A quadratic form is positive definite when q(x)>0 for every non-zero x, and since q=λ1u2+λ2v2+ in the eigenvector basis, that happens exactly when every eigenvalue is positive. Negative definite means all negative, and indefinite means mixed signs, which is a saddle.

For a two by two there is a shortcut that avoids finding the eigenvalues: the form is positive definite exactly when a>0 and detA>0. The determinant is the product of the eigenvalues, so a positive determinant means they share a sign, and a=q(1,0) being positive settles which sign. For [(2,2),(2,3)]: a=2>0 and det=6-4=2>0, so positive definite, and the eigenvalues confirm it, being (5±17)/2=4.562 and 0.438.

This is the multivariable second derivative test, and anyone who has taken calculus has met it in disguise. At a critical point of a function of several variables, the matrix of second partial derivatives, the Hessian, is symmetric because mixed partials are equal. If it is positive definite the point is a minimum, since the surface curves upward along every direction; negative definite gives a maximum; indefinite gives a saddle. The two by two condition a>0 with det>0 is precisely the rule usually quoted as fxx>0 and fxxfyy-fxy2>0.

Example. Is the form q(x,y)=4x2-4xy+3y2 positive definite?

The matrix is [(4,-2),(-2,3)]. Here a=4>0 and det=12-4=8>0, so yes. The eigenvalues, from λ2-7λ+8=0, are (7±17)/2=5.561 and 1.439, both positive, confirming it. The level curves are ellipses.

Now you. Classify q(x,y)=x2+6xy+y2.

Answer

The matrix is [(1,3),(3,1)], with det=1-9=-8<0. A negative determinant means the eigenvalues have opposite signs, so the form is indefinite: it is positive along (1,1), where q=8, and negative along (1,-1), where q=-4. The level curves are hyperbolas and the origin is a saddle.

Where symmetric matrices come from

They are not rare. Three sources supply most of the symmetric matrices anyone meets.

Any matrix at all generates one: ATA is symmetric, since (ATA)T=AT(AT)T=ATA, and it is positive semidefinite, since xTATAx=(Ax)(Ax)=Ax20. That is the matrix at the heart of the normal equations four lessons ago, and its being positive definite whenever the columns of A are independent is what made the least squares solution unique.

Physical laws that pair a cause with an effect are usually symmetric, because the underlying energy is a quadratic form: the stiffness matrix of a structure, the inertia tensor of a rigid body, the conductivity of a crystal. Diagonalising the inertia tensor gives the principal axes about which a body spins without wobbling, which is a physical fact recovered by an eigenvector computation.

And covariance matrices are symmetric by construction, since the covariance of x with y equals the covariance of y with x. Diagonalising one is principal component analysis, which finds the directions of greatest variation in data.

Principal components, on four points

Take the data (2,1), (3,3), (4,3) and (5,5). The mean is (3.5,3), so the centred points are (-1.5,-2), (-0.5,0), (0.5,0) and (1.5,2). Dividing the sums of products by n-1=3 gives the variances Sxx=5/3=1.6667 and Syy=8/3=2.6667 and the covariance Sxy=6/3=2. The covariance matrix [(1.6667,2),(2,2.6667)] has trace 4.3333 and determinant 4.4444-4=0.4444, so the eigenvalues satisfy λ2-4.3333λ+0.4444=0, giving λ1=4.2282 and λ2=0.1051.

The first eigenvalue accounts for 4.2282/4.3333=97.6 per cent of the total variance, so the cloud is very nearly one-dimensional. Its direction solves (1.6667-4.2282)v1+2v2=0, that is v2=1.2808v1, so the principal direction is (1,1.2808), or as a unit vector (0.6154,0.7882). Projecting the data onto that single direction loses under three per cent of the variation, which is data compression by eigenvector, and it is the same computation performed on matrices with thousands of rows.

Example. The four points above have covariance eigenvalues 4.2282 and 0.1051. What fraction of the variance survives if the data is projected onto the second principal direction instead of the first?

The total variance is the trace, 4.3333, and the second eigenvalue is 0.1051, so the fraction is 0.1051/4.3333=0.0243, under two and a half per cent. Keeping the wrong direction discards almost everything, which is why the eigenvalues are always sorted before any are thrown away.

Now you. A covariance matrix in three dimensions has eigenvalues 8.0, 1.5 and 0.5. How much of the variance is captured by the first two principal directions?

Answer

The total is 8.0+1.5+0.5=10.0, and the first two account for 9.5, or 95 per cent. Dropping the third direction turns three-dimensional data into two-dimensional data at a cost of five per cent of the variation, which is the trade principal component analysis exists to make.

Honest limits, and what comes after

The spectral theorem needs the matrix to be genuinely symmetric, and near-symmetry buys nothing in theory, though in practice a small asymmetry perturbs the eigenvalues only slightly, which is the sense in which symmetric problems are well conditioned. The theorem as stated is for real matrices; the complex analogue replaces the transpose by the conjugate transpose and symmetric by Hermitian, and the whole of quantum mechanics is built on that version, where the real eigenvalues are the possible measured values of an observable.

The obvious gap is that most matrices are neither symmetric nor square. The repair is the singular value decomposition: every m by n matrix, with no assumptions whatever, can be written A=UΣVT with U and V orthogonal and Σ diagonal with non-negative entries. Geometrically it says that every linear map is a rotation or reflection, followed by a scaling along perpendicular axes, followed by another rotation or reflection: no shear survives once the input and output are allowed their own bases. It follows from this lesson, since the axes are the eigenvectors of the symmetric matrices ATA and AAT, and the singular values are the square roots of their shared eigenvalues. It is what a numerical library actually computes when asked for a rank, a condition number, a least squares fit or a low-rank approximation, and it is the natural next subject after this one.

Look back at what a matrix has become. It began in the first lesson as a bookkeeping device for the coefficients of a system nobody wanted to write out twice. It is now a transformation of space, whose columns say where the basis goes, whose determinant says what it does to area, whose rank and null space say what it destroys, and whose eigenvectors are the directions it treats as its own. Reading those five things off a matrix is what it means to see one as a transformation, and it is what this course was for.

Linear Algebra, from libre.university