Solution (source code)

= Solution

A best approximation to $x$ from $U_n$ is a vector $u_*\in U_n$ such that
$$
\boxed{\|x-u_*\|=\inf_{u\in U_n}\|x-u\|.}
$$
The definition requires attainment of the infimum. This finite-dimensional subspace does have such an approximation, as the explicit projection below shows; <completeness> of the whole inner-product space is unnecessary.