Login
📚 Differential Equations for Engineers
Chapters ▾

A.5 Inner Product and Projections

Inner Product and Orthogonality

To do basic geometry, we need length, and we need angles. We have already seen the euclidean length, so let us figure out how to compute angles. Mostly, we are worried about the right angleto the power 1.

Given two (column) vectors in n, we define the (standard) inner product as the dot product:

x,y=x·y=yTx=x1y1+x2y2++xnyn=i=1nxiyi.

Why do we seemingly give a new notation for the dot product? Because there are other possible inner products, which are not the dot product, although we will not worry about others here. An inner product can even be defined on spaces of functions as we do in Chapter 4:

f(t),g(t)=abf(t)g(t)dt.

But we digress.

The inner product satisfies the following rules:

  1. x,x0, and x,x=0 if and only if x=0,
  2. x,y=y,x,
  3. ax,y=x,ay=ax,y,
  4. x+y,z=x,z+y,z and x,y+z=x,y+x,z.

Anything that satisfies the properties above can be called an inner product, although in this section we are concerned with the standard inner product in n.

The standard inner product gives the euclidean length:

x=x,x=x12+x22++xn2.

How does it give angles?

You may recall from multivariable calculus, that in two or three dimensions, the standard inner product (the dot product) gives you the angle between the vectors:

x,y=xycosθ.

That is, θ is the angle that x and y make when they are based at the same point.

In n (any dimension), we are simply going to say that θ from the formula is what the angle is. This makes sense as any two vectors based at the origin lie in a 2-dimensional plane (subspace), and the formula works in 2 dimensions. In fact, one could even talk about angles between functions this way, and we do in Chapter 4, where we talk about orthogonal functions (functions at right angle to each other).

To compute the angle we compute

cosθ=x,yxy.

Our angles are always in radians. We are computing the cosine of the angle, which is really the best we can do. Given two vectors at an angle θ, we can give the angle as θ, 2πθ, etc., see Figure 1. Fortunately, cosθ=cos(θ)=cos(2πθ). If we solve for θ using the inverse cosine cos1, we can just decree that 0θπ.

Picture of the angle between two vectors.  Arc arrow from y to x with angle theta.  Backwards is -theta.
Figure 1: Angle between vectors.

As we said, the most important angle is the right angle. A right angle is π2 radians, and cos(π2)=0, so the formula is particularly easy in this case. We say vectors x and y are orthogonal if they are at right angles, that is if

x,y=0.

The vectors (1,0,0,1) and (1,2,3,1) are orthogonal. So are (1,1) and (1,1). However, (1,1) and (1,2) are not orthogonal as their inner product is 3 and not 0.

Orthogonal Projection

A typical application of linear algebra is to take a difficult problem, write everything in the right basis, and in this new basis the problem becomes simple. A particularly useful basis is an orthogonal basis, that is a basis where all the basis vectors are orthogonal. When we draw a coordinate system in two or three dimensions, we almost always draw our axes as orthogonal to each other.

Generalizing this concept to functions, it is particularly useful in Chapter 4 to express a function using a particular orthogonal basis, the Fourier series.

To express one vector in terms of an orthogonal basis, we need to first project one vector onto another. Given a nonzero vector v, we define the orthogonal projection of w onto v as

projv(w)=(w,vv,v)v.

For the geometric idea, see Figure 2. That is, we find the "shadow of w" on the line spanned by v if the direction of the sun’s rays were exactly perpendicular to the line. Another way of thinking about it is that the tip of the arrow of projv(w) is the closest point on the line spanned by v to the tip of the arrow of w. In terms of euclidean distance, u=projv(w) minimizes the distance wu among all vectors u that are multiples of v. Because of this, this projection comes up often in applied mathematics in all sorts of contexts we cannot solve a problem exactly: We can’t always solve "Find w as a multiple of v" but projv(w) is the best "solution."

Function graph showing the parametric curve (t*cos(a), t*sin(a)) for t in [-7, 7], the parametric curve (3*t, 4*t) for t in [0, 1], the parametric curve ((3*cos(a)+4*sin(a))*cos(a)*t, (3*cos(a)+4*sin(a))*sin(a)*t) for t in [0, 1] and the parametric curve ((3*cos(a)+4*sin(a))*cos(a) + (3 - (3*cos(a)+4*sin(a))*cos(a))*t, (3*cos(a)+4*sin(a))*sin(a) + (4 - (3*cos(a)+4*sin(a))*sin(a))*t) for t in [0, 1]. Adjustable parameter: Direction of v (a) = 0.79 rad. Viewing window: x from -5.91 to 7.91, y from -3.47 to 5.07.
w = (3, 4) in blue, the line spanned by v dashed green, proj_v(w) in orange, and w − proj_v(w) dashed in purple — drawn from the tip of the projection to the tip of w, so the right angle is the one you can actually see. Drag the direction a to sweep the shadow along the line: the purple segment meets the green line at a right angle at every single setting, which is the check this section runs once by hand. At a = 0.7854 (π/4) the projection is (3.5, 3.5) = (7/2)·(1, 1) and at a = −0.7854 it is (−0.5, 0.5) = (−1/2)·(1, −1) — the very coefficients this section computes for (3, 4) in the orthogonal basis (1, 1), (1, −1). Push a past −0.64, where tan a = −3/4, and the projection collapses to a point, because there v ⟂ w and the shadow is nothing at all.
A 3D scene showing the vector v = (2, 1, c) as an orange segment from the origin, its orthogonal projection (2, 1, 0) as a blue segment lying in the translucent xy-plane, and a vertical dashed-style drop line connecting the tip of v to the tip of its projection. Dragging the slider changes only the height c of v; the blue projection in the plane stays fixed, showing that projection discards exactly the component perpendicular to the plane.Explore in 3D (opens in a new tab)
The vector v = (2, 1, c) in orange, its orthogonal projection (2, 1, 0) onto the xy-plane in blue, and the perpendicular drop between them. Drag the slider for c: the projection never moves - projecting onto the plane simply discards the component orthogonal to it.
Picture of the orthogonal projection right triangle with sides w and proj_v(w), with proj_v(w) in the direction of v.
Figure 2: Orthogonal projection.

The formula follows from basic trigonometry. The length of projv(w) should be cosθ times the length of w, that is (cosθ)w. We take the unit vector in the direction of v, that is, vv and we multiply it by the length of the projection. In other words,

projv(w)=(cosθ)wvv=(cosθ)wvv2v=w,vv,vv.

Orthogonal Basis

As we said, a basis v1,v2,,vn is an orthogonal basis if all vectors in the basis are orthogonal to each other, that is, if

vj,vk=0

for all choices of j and k where j=k (a nonzero vector cannot be orthogonal to itself). A basis is furthermore called an orthonormal basis if all the vectors in a basis are also unit vectors, that is, if all the vectors have magnitude 1. For example, the standard basis {(1,0,0),(0,1,0),(0,0,1)} is an orthonormal basis of 3: Any pair is orthogonal, and each vector is of unit magnitude.

The reason why we are interested in orthogonal (or orthonormal) bases is that they make it really simple to represent a vector (or a projection onto a subspace) in the basis. The simple formula for the orthogonal projection onto a vector gives us the coefficients. In Chapter 4, we use the same idea by finding the correct orthogonal basis for the set of solutions of a differential equation. We are then able to find any particular solution by simply applying the orthogonal projection formula, which is just a couple of a inner products.

Let us come back to linear algebra. Suppose that we have a subspace and an orthogonal basis v1,v2,,vn. We wish to express x in terms of the basis. If x is not in the span of the basis (when it is not in the given subspace), then of course it is not possible, but the following formula gives us at least the orthogonal projection onto the subspace, or in other words, the best approximation in the subspace.

First suppose that x is in the span. Then it is the sum of the orthogonal projections:

x=projv1(x)+projv2(x)++projvn(x)=x,v1v1,v1v1+x,v2v2,v2v2++x,vnvn,vnvn.

In other words, if we want to write x=a1v1+a2v2++anvn, then

a1=x,v1v1,v1,a2=x,v2v2,v2,,an=x,vnvn,vn.

Another way to derive this formula is to work in reverse. Suppose that x=a1v1+a2v2++anvn. Take an inner product with vj, and use the properties of the inner product:

x,vj=a1v1+a2v2++anvn,vj=a1v1,vj+a2v2,vj++anvn,vj.

As the basis is orthogonal, then vk,vj=0 whenever k=j. That means that only one of the terms, the jth one, on the right hand side is nonzero and we get

x,vj=ajvj,vj.

Solving for aj we find aj=x,vjvj,vj as before.

If the basis is orthonormal rather than orthogonal, then all the denominators are one. It is easy to make a basis orthonormal—divide all the vectors by their size. If you want to decompose many vectors, it may be better to find an orthonormal basis. In the example above, the orthonormal basis we would thus create is

(12,12),(12,12).

Then the computation would have been

(3,4)=(3,4),(12,12)(12,12)+(3,4),(12,12)(12,12)=72(12,12)+12(12,12).

Maybe the example is not so awe inspiring, but given vectors in 20 rather than 2, then surely one would much rather do 20 inner products (or 40 if we did not have an orthonormal basis) rather than solving a system of twenty equations in twenty unknowns using row reduction of a 20×21 matrix.

As we said above, the formula still works even if x is not in the subspace, although then it does not get us the vector x but its projection. More concretely, suppose that S is a subspace that is the span of v1,v2,,vn and x is any vector. Let projS(x) be the vector in S that is the closest to x. Then

projS(x)=x,v1v1,v1v1+x,v2v2,v2v2++x,vnvn,vnvn.

Of course, if x is in S, then projS(x)=x, as the closest vector in S to x is x itself. But true utility is obtained when x is not in S. In much of applied mathematics, we cannot find an exact solution to a problem, but we try to find the best solution out of a small subset (subspace). The partial sums of Fourier series from Chapter 4 are one example. Another example is least square approximation to fit a curve to data. Yet another example is given by the most commonly used numerical methods to solve partial differential equations, the finite element methods.

Gram–Schmidt Process

Before leaving orthogonal bases, let us note a procedure for manufacturing them out of any old basis. It may not be difficult to come up with an orthogonal basis for a 2-dimensional subspace, but for a 20-dimensional subspace, it seems a daunting task. Fortunately, the orthogonal projection can be used to "project away" the bits of the vectors that are making them not orthogonal. It is called the Gram-Schmidt process.

We start with a basis of vectors v1,v2,,vn. We construct an orthogonal basis w1,w2,,wn as follows.

w1=v1,w2=v2projw1(v2),w3=v3projw1(v3)projw2(v3),w4=v4projw1(v4)projw2(v4)projw3(v4),wn=vnprojw1(vn)projw2(vn)projwn1(vn).

What we do is at the kth step, we take vk and we subtract the projection of vk to the subspace spanned by w1,w2,,wk1.

Footnotes

[1] When Euclid defined angles in his Elements, the only angle he ever really defined was the right angle.

Adapted from Differential Equations for Engineers by Jiří Lebl (Oklahoma State University), hosted on LibreTexts (math.libretexts.org) and licensed under CC BY-SA 4.0. Changes were made. License: CC-BY-SA-4.0.