linear-algebra-and-numerical-analysis
Intro to linear algebra
Spans and linear combinations
A linear combination of two vectors (, ) is, where (a,b) are scalars:
The span of two vectors and is the set of all their linear combinations.
- In 2D, two non-collinear vectors typically span the whole plane.
- If two vectors line up (one is a scalar multiple of the other), they span only a line.
Based on span, we have the concept of linear dependence vs independence:
- Linearly dependent: one vector can be expressed as a linear combination of others (redundant).
- Linearly independent: no vector in the set is redundant.
Checking for linear independence
Given two vectors and , you test for linear independence by setting their linear combination equal to the zero vector.
- If the only solution is that both and are , then they are linearly dependent.
- If there is a solution with either and not being the zero vector, then they are linearly dependent.
Matrices as linear transformations
A matrix has its columns as basis vectors, and applies a transformation to vectors by using the matrix's basis vectors as the basis vectors for the vector it wants to transform, mapping that vector into the matrix's coordinate space.
Here is how a matrix translates a vector in standard coordinate space (basis vectors are and ) into a vector .
NOTE
has a solution if is in the span of the columns of .
You can describe a linear transformation by just recording what happens to the and basis vectors of the original coordinate space and how they get transformed.
For example, if a linear transformation scales to , then the matrix representation of the linear transformation is , or
For this example, let's assume and .
- The basis vectors of , let's call them and
- When we transform into the coordinate space of , basically we're going to change the linear combination representation of from using the standard coordinate space basis vectors ( and ) to the basis vectors of :
- But this is now in the "language" of the non-standard basis vectors and , and the only way for us to understand what truly happened to is to translate the basis vectors into the standard coordinate space and then rewrite everything as a linear combination in the standard space:
Matrix multiplication properties
- Not commutative: (AB \ne BA) in general.
- Associative: (A(BC)=(AB)C).
- applied right to left: Applying one transformation after another is composition. If you first apply (B) then apply (A), the combined transformation is (AB), because matrix multiplication is applied right to left.
Change of basis
Let's assume
Determinants and invertible matrices
The geometric meaning of a determinant
For a 2×2 matrix, () is how much areas scale.
- (): areas expand
- (): areas shrink
- (): orientation flips (a “mirror”/reflection component)
But what if the determinant is 0, meaning the basis vectors are collinear with each other? That's where determinants connect to linear independence and dependence and singular matrices:
- : space gets “squished” into a lower dimension (e.g., plane → line).
- linearly dependent: basis vectors become linearly dependent.
- singular: since the columns of the matrix (basis vectors) are linearly dependent, matrix is singular.
- : the parallelogram formed by the basis vectors has non-zero area
- linearly dependent: basis vectors are not collinear, since that is the only way for the parallelogram formed by the basis vectors to have non-zero area
- singular: since the columns of the matrix (basis vectors) are linearly dependent, matrix is singular.
Mathematical properties of determinants
-
multiplicative rule: if a matrix gets transformed via composition by matrix , then the area formed by its basis vectors () gets scaled by the area formed from the basis vectors of , namely .
-
inverse rule
-
additive rule
Invertible and singular matrices
To represent a system of equations, you can use a coefficient matrix, multiply it by a variable vector, and set it equal to a constants vector: .
In plain english:
We are looking for a vector that when transformed by , lands on .
To solve this system of equations, we can use inverse matrices: Inverse matrices are the inverse transformation of a matrix.
By applying a transformation, then subsequently applying the inverse of that transformation, you end up back where you started: .
- If a matrix rotates space clockwise by 90 degrees, an inverse matrix of that matrix would rotate space counterclockwise 90 degrees.
- doing a transformation then doing the transformation is the same thing as doing nothing.
By using the inverse, you can find the variable vector like so
A matrix is invertible/nonsingular if it has an inverse, else we call it singular if it does not have an inverse.
Singular matrices are noninvertible (have det = 0) while nonsingular matrices are invertible. In terms of G.E, this means the following:
- singular matrices: infinite solutions or no solutions. One row is just full zeros when reduced via G.E, so there is at least one free variable.
- nonsingular: Has one solution for , meaning there is a pivot in each row and along the diagonals in its correct spot.
when matrices don’t have an inverse
If the determinant of matrix is 0, then it does not have an inverse because it squishes all of space onto one line irreversibly. The area of the parallelogram formed by the basis vectors is 0. You cannot un-squish a line.
Also, a matrix transformation being injective and surjective plays a role in if its invertible or not.
- injective: A linear map is injective iff the only vector mapped to (0) is the zero vector.
- Basically, no transformed vector besides the zero vector should transform to the zero vector, otherwise the linear transformation is not injective.
- surjective: Once transformed, the new basis matrix has the same span as the original basis matrix. Basically, the transformation matrix must be full rank and a square matrix.
Transformation matrices will only have inverses if they are bijective - meaning both injective and surjective.
So in summary, here are the three cases where a transformation matrix will not have an inverse:
- : transformation matrix is not injective, because some vectors will get squished to the zero vector as a result of this transformation.
- nonsquare matrices: Not surjective, since their column space is not full rank.
- matrices that transform some vectors to the : These matrices are not injective by definition.
Rank, column space, null space
- Rank: number of dimensions in the output / the dimension of the column space.
- Column space: the span of the columns of ().
- null space: The null space is all vectors mapped to zero, which can be found through this equation:
rank
rank means the number of dimensions in the output of the transformation, and is used to differentiate between transformations that either take up all the possible dimensions or have a zero-determinant and thus squish all vectors into a lower dimension.
- When the output of a transformation is a line, the rank is 1.
- When the output of a transformation is a plane, the rank is 2.
- When the output of a transformation is all of space, the rank is 3.
- Full rank means that the number of dimensions matches the number of columns.
- example: full rank for an space is 4.
IMPORTANT
Matrices are full rank iff they are injective, meaning its null space only has the trivial solution .
column space
Column space is the span of the columns of the matrix, with the max column space for a matrix being .
- when a matrix is singular based on column space: If your column space dimensions are less than the dimensions of the matrix, meaning less dimensional than , then the matrix is singular.
null space
The null space is the set of all possible vectors that become null, or after a linear transformation.
Geometrically, it's the set of all vectors that land on the origin after a linear transformation, and has two types of solutions:
- trivial solution: the only vector that maps to the origin is the origin itself, , since by nature of a linear transformation the origin (zero vector) always stays fixed.
- nontrivial solution: there is a non-empty set of non-zero vectors called the kernel that gets transformed into the .
You can find the null space by solving a system of equations and setting the post-transformed vector to the .
NOTE
The kernel is the set of all solutions to the null space equation, and a trivial solution leads to a trivial kernel, and a nontrivial solution leads to a nontrivial kernel.
Cramer's rule
Cramer's rule comes into play when we have an equation , where and are known, and we want to find out what is.
Intuition
Consider that for the standard identity matrix with basis vectors and , we can represent the coordinates of a vector as two areas.
Let's form the following notation:
- : the area of the parallelogram formed by and
- : the area of the parallelogram formed by and
Let's dive into the calculations
- : the area of the parallelogram formed by and turns out to be .

- : the area of the parallelogram formed by and turns out to be .

Now that we found what and are in terms of basis vectors, we can swap those standard basis vectors out for any matrix, and understand that linear transformations will scale and stretch vectors evenly:

- , but after transformation from A, it becomes , and now find the signed area using the output vector , since , thus we deal with instead of in the transformed coordinate space of and luckily since we know , thus we arrive at this new formula:

- , but after transformation from A, it becomes , and now find the signed area using the output vector , since , thus we deal with instead of in the transformed coordinate space of and luckily since we know , thus we arrive at this new formula:

Dot product
For two vectors and , the dot product can be thought of as the length of projected on times the length of
- When two vectors point in generally the same direction, their dot product is positive
- Whe two vectors point in generally the opposite directions, their dot product is negative.
This is another formula for the dot product that lets you find the angle between two vectors:
Geometric interpretation
For two vectors and , the dot product can be thought of as the length of projected on times the length of .
Here's how to geometrically visualize and :
- Think that you are projecting onto , so draw a line down from the tip of towards until you hit , and that line should form a right triangle, with and .

- Now multiply the length of the projected onto by the length of to achieve the dot product .

- Notice that this operation is commutative, where yields the same result, even though now we're projecting onto instead. This is because both geometric interpretations are exact mirror opposites of each other.


- Even with scalar multiplication that breaks symmetry, the overall effect is still the same if you go through the math:
- : The length of projected onto doesn't change, but we now multiply by , which doubles the dot product.
- : The length of projected onto does change, but it approximately doubles the length of the previous projection of onto , so the overall effect still doubles the dot product.

Now let's understand how this geometric interpretation works with other cases:
- vectors point in roughly same direction: results in a positive length
- vectors point in roughly opposite directions: results in a negative length

- vectors are perpendicular: geometrically, to form a projection you draw a line straight down from the tip of the vector you're trying to project onto the other vector. You can't do it if they're perpendicular, which is why the dot product is zero if the vectors are perpendicular, Because there's no way to draw a projection from one vector onto another if the vectors are perpendicular

Algebraic duality interpretation
Great. Now we know that dot products correspond to projections but we need to understand why the mathematical way of just ordered coordinate pair multiplication of dot products actually corresponds to a projection.
The way we can view this is through duality, which considers vectors as linear transformations that squish space onto a lower dimension, namely a single number line:
- linear transformations that squish space onto a line have basis vectors land on a number in the number line.
Consider an example and , and we are doing , which has the duality interpretation of transforming into the coordinate space (single number line) of using the basis vectors of being and , so we can rewrite the dot product as a linear transformation which ends up being just a linear combination:

Projections
Although the dot product may seem asymmetric since the vector you are projecting is different depending on which vector comes first in the dot product, in the end they both calculate out to be the exact same thing.
This allows us to find the lengths of the individual projections even if the dot product is the same.
Let's start off with some notation:
Orthonormal transformations
here's a thought: in the standard coordinate space, we can represent an arbitrary vector like so:
So we would naively think that we can represent any vector as the sum of its dot products with each basis vector of a matrix.
But that only works in one special case: orthonormal transformations.
Orthonormal transformations are those in which the dot product of two vectors is preserved even after the same matrix transformation is applied to those two vectors.

The only matrices that provide orthonormal transformations are of the orthogonal family of matrices, where vectors 1) are not stretched and 2) maintain the same angle.
More formally, matrices that provide orthonormal transformations must satisfy these two properties:
- : Because the basis vectors are uniform, transformed vectors are not stretched.
NOTE
So what does it really mean to have a matrix be representative of an orthonormal transformation?
Their rows and columns form orthonormal sets of vectors, which means they preserve the inner product of vectors, thus maintaining lengths and angles in complex vector spaces, which leads to the determinant having an absolute value of 1.
In the case of orthonormal transformations you can very easily find an input vector that results in a corresponding known output vector via these steps:

inner products vs outer products
Suppose you have two vectors of the same length, and such that
- inner product: The inner product, also known as the dot product, is
- outer product: The outer product produces an matrix.
Cross product
The cross product of two vectors and measures the area of the parallelogram formed by those two vectors:
Here are the behaviors of a cross product:
- greatest when two vectors are orthogonal: This is because .
- : this is because the angle between a vector and itself is 0, therefore
Eigenvectors and Eigenvalues
Eigenvectors are simply vectors that stay on their span after a linear transformation. More formally, they satisfy the equation :
- Eigenvector: a vector that stays on its own span after transformation.
- Eigenvalue: the factor by which that eigenvector is scaled.
- Eigenpair: the pair of an eigenvector and its corresponding eigenvalue
To compute eigenvalues, we can try to find the null space of , which will then give us all the eigenpairs possible.
So we start off with this:
If , then . Which then gives us the characteristic equation we can solve for as a polynomial:
NOTE
The reasoning is that the only way for a matrix times a vector to be the is if the matrix has a nontrivial null space and therefore is not full rank, and therefore the matrix is singular, therefore, the determinant of the matrix is 0.
You can now also use determinants to solve for eigenvectors and eigenvalues.
- Solve the polynomial for all the possible
- Plug in into to solve for the eigenvectors
Solving for eigenpairs
Here are the general steps:
-
Rewrite to
-
Since comparing matrix-vector multiplication with scalar-vector multiplication is awkward, we can rewrite as , which will just put the eigenvalues along the diagonal of the matrix.
-
If , then . The reasoning is that the only way for a matrix times a vector to be the is if the matrix has a null space and is therefore non-invertible and therefore has a determinant = 0. Use this equation to find the eigenvalues.
-
Plug back in the eigenvalues you found when you solved for back into the equation and solve for the eigenvectors:
NOTE
A quick tip to find eigenvalues:
If produces a triangular matrix or a diagonal matrix, then the eigenvalues simply lie along the diagonal of . Proof and intuition in [[#Diagonal matrices and eigenvalues]].
Eigenvalue theorems
proof: The determinant of a matrix is equal to product of its eigenvalues
Prove that the determinant of an matrix equals the product of its eigenvalues because the determinant is precisely the constant term of the matrix's characteristic polynomial.
The determinant of a matrix is equal to product of its eigenvalues:
How do we prove this?
Proof via the Characteristic Polynomial
Every eigenvalue of satisfies the characteristic equation:
Let . Because is an matrix, is a monic polynomial of degree . By the Fundamental Theorem of Algebra, can be factored completely over the complex numbers in terms of its roots (the eigenvalues , counted with multiplicity):
Now, evaluate both representations of at :
-
Determinant definition:
Factoring out the scalar from all rows yields:
-
Factored roots definition:
Equating the two expressions for :
Dividing both sides by leaves:
Alternative Proof via Schur Decomposition
In numerical linear algebra, this result is often viewed through the Schur Decomposition ( a generalization of diagonalization), which states that any square matrix can be factored as:
where is unitary () and is upper triangular.
-
The diagonal entries of () are precisely the eigenvalues of .
-
Using the multiplicative property of determinants:
-
Because is upper triangular, its determinant is simply the product of its diagonal entries:
Both paths reach the same conclusion: if any eigenvalue , the entire product collapses to zero, which is why a matrix with a zero eigenvalue is non-invertible.
Therefore, for any matrix :
NOTE
Coming from this theorem, if a matrix has an eigenvalue , then it has a determinant = 0 and is thus noninvertible (the product of eigenvalues becomes 0, thus determinant becomes 0).
Diagonal matrices and eigenvalues
For both diagonal and triangular (upper or lower) matrices, the eigenvalues are simply the entries along the main diagonal.
NOTE
An intuitive look:
If a matrix is diagonal, the standard basis vectors are eigenvectors and diagonal entries are eigenvalues.
For both diagonal and triangular (upper or lower) matrices, the eigenvalues are simply the entries along the main diagonal.
Why This Holds
For any upper triangular matrix :
The eigenvalues are the roots of the characteristic equation .
Subtracting from yields another upper triangular matrix:
Because the determinant of any triangular (or diagonal) matrix is the product of its diagonal entries:
Setting this polynomial to zero gives the roots directly:
Since a diagonal matrix is merely a special case of a triangular matrix (where all off-diagonal elements are zero), the exact same rule applies.
Significance in Numerical Analysis
Finding the roots of a high-degree polynomial directly is computationally unstable and expensive for large matrices. Because triangular and diagonal matrices reveal their eigenvalues by inspection, nearly all numerical eigenvalue algorithms work by transforming a general matrix into one of these simpler forms via similarity transformations (), which preserve eigenvalues:
- Eigendecomposition (): Transforms a diagonalizable matrix into a pure diagonal matrix , where the diagonal holds the eigenvalues and the columns of are the eigenvectors.
- Schur Decomposition (): Transforms any square matrix using a unitary matrix into an upper triangular matrix (Schur form). The eigenvalues are read directly off the diagonal of .
- QR Algorithm: The workhorse method in numerical linear algebra; it iteratively applies QR factorizations to drive a general matrix toward upper triangular (or quasi-triangular) form so the eigenvalues can be read straight off the diagonal.
Algebraic matrix properties
Inverse and transpose proofs
These are general proofs that work with all square matrices:
proof 1
We want to prove:
proof 2
We want to prove:
Vector and matrix norms
Vector norms
A vector norm is a function that transforms a vector of any size into a scalar.
A vector norm is only valid if it satisfies these four properties:

- positive: the norm returns a positive real number
- injective: the norm is 0 only if the input is .
- preservation of scalars: scalars in scalar multiplication can be taken out of the norm.
- satisfies triangle inequality
There are three vectors norms:
- L1 norm: the sum of the absolute value of all the elements in the vector
- L2 norm: the magnitude of the vector
- infinity norm: the element with the maximum absolute value out of all the elements in the vector.
1 norm
The 1-norm is simply the sum of the absolute value of all the elements in the vector
2 norm
The 2-norm is the most common vector norm, which is just the magnitude of the vector
infinity-norm
The infinity-norm is simply the maximum absolute value of the elements in the vector.
Norm comparisons
Matrix norms
Matrix norm is a function that takes in a matrix and returns a single scalar value.
A matrix norm aggregates all the values inside it, and must have these properties:

Matrix norms measure how much a matrix can stretch a vector:
Common induced norms include .
L2 Norm (Frobenius Norm)
For matrices, the L2 norm is just the sum of the squares of all the elements in the matrix, and then take the square root of that.
This norm is also called the Frobenius Norm.
np.linalg.norm(matrix) # returns frobenius norm of matrix
Special matrices
Diagonal matrices
Diagonal matrices have these three core properties:
- eigenvalues lie along the diagonal:
- The product of the diagonals of a diagonal matrix is equal to the product of the eigenvalues.
- the trace of a diagonal matrix is equal to the sum of the eigenvalues of the diagonal matrix.
-
diagonal matrix exponents are just exponentiating the diagonal elements: This means it’s trivial to calculate something like .
-
matrix multiplication is commutative: If you have a diagonal matrix and a nondiagonal matrix , then matrix multiplication is commutative with diagonal matrices.
Diagonal proofs
determinant of a diagonal matrix is product of its diagonal elements and thus eigenvalues
A matrix’s determinant is equal to the product of its eigenvalues, so since diagonal elements in a diagonal matrix are the eigenvalues, the determinant of a diagonal matrix is equal to the product of its diagonal values.
Symmetric matrices
A symmetric matrix is a matrix that is equal to its transpose
Orthogonal, unitary, and Hermitian matrices
Decompositions
Cholesky decomposition
Eigendecomposition
You can represent any matrix with linearly independent eigenvectors as its eigendecomposition, which you can get by manipulating the eigenvector formula , which only works for square and invertible matrices .
Starting from a invertible matrix :
- : the diagonal matrix with eigenvalues of along the diagonal.
- : the matrix of eigenvectors of , which we often normalize to be unit vectors.
- : the diagonal matrix with the corresponding eigenvalues of along the diagonal, gotten from the neat trick of
Here are the steps:
- Find the eigenpairs of
- We can form the matrix as the matrix whose columns are the eigenvectors of .
- From the standard eigenvector equation , that corresponds to the matrix version , where , the diagonal matrix with the corresponding eigenvalues of along the diagonal.
- Multiply both sides by
From these to steps, we arrive this equation:
Similarity transforms, diagonalization, and Schur
Similarity transform
- Same eigenvalues.
- Same determinant, trace, characteristic polynomial.
Diagonalization (special case)
If has independent eigenvectors:
Schur decomposition (more general)
Every square matrix has a Schur form (over complex numbers):
where is unitary and is upper triangular.
Numerical relevance:
- Many eigenvalue algorithms are based on Schur form because it’s stable.