30 Projection & residual
Many problems in physics and engineering involve the task of decomposing a vector
The hat-shaped crown in
The gravitational force on an object always points downward toward the center of the Earth. For an isolated object—often the word “mass” is used instead of “object”—acceleration is in the same downward direction. However, often the mass is just one component in a mechanically interconnected system, such as the three systems shown in Figure 30.2: a ramp, a pendulum, and an inclined plane. The other components of the system counteract, to some extent, the gravitational force on the mass. The net force on the mass—taking into account gravity and the forces imposed by the other elements of the system—is in a direction
The
The above example shows just one way the task of vector decomposition arises. Our particular interest in this part of the book is in a more general task: finding how to take a linear combination of the columns of a matrix
30.1 Projection terminology
In a typical vector decomposition task, the setting determines the relevant direction or subspace. The decomposition is accomplished by projecting the vector onto that direction or subspace. The word “projection” may bring to mind the casting of shadows on a screen in the same manner as an old-fashioned slide projector or movie projector. The light source and focusing lens generate parallel rays that arrive perpendicular to the screen. A movie screen is two-dimensional, a subspace defined by two vectors. Imagining those two vectors to be collected into matrix
the target vector the model vector the residual vector the model space (or “model subspace”)
Projection is the process of finding, from all the vectors in the model subspace, the particular vector
Figure 30.3 shows a solved projection problem in 3-dimensional space. The figure can be rotated or set spinning, which makes it much easier to interpret the diagram as a three-dimensional object. In addition to the target vector
Interpreting such three-dimensional diagrams on a printed page can be difficult. Better to rotate them interactively. For instance, to see that the translucent plane in Figure 30.3 contains
30.2 Projection onto a single vector
As we said, projection involves a vector
Figure 30.4 diagrams the situation of projecting the target vector
The angle between
Knowing
Scaling
.
In R/mosaic, calculate the projection of %onto%
. For instance
<- rbind(-1, 2)
b <- rbind(-2.5, -0.8)
a <- b %onto% a
s
s## [,1]
## [1,] -0.3265602
## [2,] -0.1044993
Having found
<- b - s
r
r## [,1]
## [1,] -0.6734398
## [2,] 2.1044993
The two properties that a projection satisfies are:
- The residual vector is perpendicular to each and every vector in
. Since in this example, contains only the one vector , we need only look at and confirm that it is zero.
%dot% a
r ## [1] -2.220446e-16
- The residual vector plus the model vector exactly equals the target vector. Since we computed
r <- b - s
, we know this must be true, but still …
+s) - b
(r## [,1]
## [1,] 0
## [2,] 0
If the difference between two vectors is zero for every coordinate, the two vectors must be identical.
30.3 Projection onto a set of vectors
As we have just seen, projecting a target
In one situation, projection is easy: when the vectors in
Consider the following matrix
<- rbind( 1, 1, 1, 1)
b <- rbind( 1, 2, 0, 0)
v1 <- rbind(-2, 1, 3, 1)
v2 <- rbind( 0, 0, -1, 3)
v3 <- cbind(v1, v2, v3) A
To confirm that v1
, v2
, and v3
are mutually orthogonal, calculate the dot product between any two of them and observe that, in each case, the result is zero.
Now construct the one-at-a-time projections: ::: {.cell layout-align=“center” fig.showtext=‘false’}
<- b %onto% v1
p1 <- b %onto% v2
p2 <- b %onto% v3 p3
To find the projection of
<- p1 + p2 + p3 b_on_A
Now we will confirm that b_on_A
is the projection of b
onto A
. The strategy is to construct the residual from the projection.
<- b - b_on_A resid
All that is needed is to confirm that the residual is perpendicular to each and every vector in A
:
%dot% v1
resid ## [1] 7.771561e-16
%dot% v2
resid ## [1] -2.220446e-16
%dot% v3
resid ## [1] 6.661338e-16
:::
30.4 A becomes Q
Now that we have a satisfactory method for projecting
We introduce the process with an example involving vectors in a 4-dimensional space.
<- rbind(1,1,1,1)
b <- rbind(2,3,4,5)
v1 <- rbind(-4,2,4,1)
v2 <- cbind(v1, v2) A
We start the construction of the
<- v1 q1
The next
<- v2 %perp% v1 q2
Since
<- (b %onto% q1) + (b %onto% q2) bhat
To confirm that this calculation of
<- b - bhat
r %dot% v1
r ## [1] 1.110223e-15
%dot% v2
r ## [1] 2.220446e-16
Note that we defined
This process can be extended to any number of vectors in
- Take the first vector from
and call it . - Take the second vector from
and find the residual from projecting it onto . This residual will be . At this point, the matrix consists of mutually orthogonal vectors. - Take the third vector from
and project it onto . We can do this because we already have an algorithm for projecting a vector onto a matrix with mutually orthogonal columns. Call the residual from this projection . It will be orthogonal to the vectors in , so all three of the q vectors we’ve created are mutually orthogonal. - Continue onward, taking the next vector in
, projecting it onto the q-vectors already assembled, and finding the residual from that projection. - Repeat step (iv) until all the vectors in
have been handled.
Project a
<- rbind(3,2,7,3,-6,4,1,-1, 8, 2) # or any set of 10 numbers
b <- rbind(4, 7, 1, 0, 3, 0, 6, 1, 1, 2)
v1 <- rbind(8, 8, 4, -3, 3, -2, -4, 9, 6, 0)
v2 <- rbind(12, 0, 4, -2, -6, -4, -1, 4, 6, -7)
v3 <- rbind(0, 3, 9, 6, -4, -5, 4, 0, 5, -4)
v4 <- rbind(-2, 5, -4, 8, -9, 3, -5, 0, 11, -4)
v5 <- cbind(v1, v2, v3, v4, v5) A
Confirm using dot products that the v
-vectors are not mutually orthogonal.
Now to construct the vectors in
<- v1
q1 <- v2 %perp% q1
q2 <- v3 %perp% cbind(q1, q2)
q3 <- v4 %perp% cbind(q1, q2, q3)
q4 <- v5 %perp% cbind(q1, q2, q3, q4)
q5 <- cbind(q1, q2, q3, q4, q5) Q
Since Q
consists of mutually orthogonal vectors, the projection of b
onto Q
can be made one vector at a time.
<- b %onto% q1
p1 <- b %onto% q2
p2 <- b %onto% q3
p3 <- b %onto% q4
p4 <- b %onto% q5
p5 # put together the components
<- p1 + p2 + p3 + p4 + p5
b_on_A # check the answer: resid should be perpendicular to A
<- b - b_on_A
resid %dot% v1
resid ## [1] 1.065814e-14
%dot% v2
resid ## [1] 4.973799e-14
%dot% v3
resid ## [1] 7.105427e-15
%dot% v4
resid ## [1] 0
%dot% v5
resid ## [1] 1.776357e-14
30.5 Exercises
Problem with NA NA
The motivation for these names will become apparent in later chapters.↩︎