The problem in brief
You are given a vector and told that a principal component of unit length points in the same direction. For the data point you must compute three things: the unit vector , the coordinate of along (the inner product, which is what PCA keeps when it reduces dimension), and the residual, the part of that this one component cannot explain. Each answer is asked in a normalised integer form and turned into a multiple-choice sum, so an arithmetic slip lands on a wrong letter.
How you are scored
Three multiple-choice parts worth 5 points each. Our answers, checked with exact fractions and with NumPy in solution.py:
| part | quantity | exact value | requested sum | choice |
|---|---|---|---|---|
| 2.1 | D | |||
| 2.2 | E | |||
| 2.3 | B |
Question by question
2.1 The unit direction
To turn into a unit vector with the same direction, divide by its length:
So , . The condition is there to make the form unique: without it, would describe the same vector. "Same direction" also fixes the sign; is a unit principal component too, but it points the other way.
: answer D.
2.2 The projection (the PCA coordinate)
Here , , and since . A tempting mistake is to rationalise the denominator, , which is not of the requested shape; another is to use instead of and report .
: answer E.
2.3 The residual
The residual is what remains of after removing its component along :
Note the shortcut in the middle: , so the square roots cancel and everything stays rational. Check (39 and 9 are odd, and 14 shares no factor 3 with them).
Two independent checks that catch almost any slip:
- Orthogonality: . The residual must be perpendicular to the direction we projected on.
- Pythagoras: must equal . It does.
: answer B.
The key idea
Projection splits a vector into two perpendicular pieces, one along a chosen direction and one orthogonal to it:

Because the two pieces are perpendicular, lengths add in squares: . Summed over a whole dataset (of centred points), this says "total variance = variance kept + reconstruction error". PCA chooses to maximise the kept part, which is the same as minimising the residuals: the first principal component is the direction with the largest variance and simultaneously the line closest to the data in the least-squares sense. Here, one direction keeps of for this point; the residual holds the other 16 %.
The full solution
solution.py computes everything with exact fractions (normalising the gcd as the statement requires) and cross-checks with floating point:
v, x = np.array([1, -2, 3]), np.array([-1, -4, 6])
a, xv = v @ v, x @ v # 14, 25
coef = Fraction(xv, a) # x.v / v.v = 25/14
r = [Fraction(int(xi)) - coef * int(vi) for xi, vi in zip(x, v)] # (-39, -6, 9)/14
Results
| part | our value | sum | choice | independent check |
|---|---|---|---|---|
| 2.1 | 16 | D | ||
| 2.2 | 39 | E | NumPy dot product | |
| 2.3 | B | and |
What to remember
- Normalise by the length: , and the PCA coordinate of is simply .
- Project with to avoid square roots: the projection does not depend on the length of .
- Residual direction and Pythagoras are two free checks that catch nearly every arithmetic error in projection problems.
- PCA is two equivalent optimisations: maximise the variance of the projections, or minimise the squared residuals; the right angle is what makes them the same problem.