Tutorials › Linear Algebra › Orthogonal Function Coefficients as Data Projections

Applications in Networks, Economics and Data · Tutorial 953 of 1000

Orthogonal Function Coefficients as Data Projections

Use dot products with orthogonal sampled-function columns to compute coefficients and understand the fitted data as a projection.

Intermediate 9 min read

What You'll Learn

  • Define orthogonality for sampled function columns using the dot product.
  • Compute coefficients by dividing each data-column dot product by the column’s squared length.
  • Interpret the discrete calculation as a finite-sample analogue of Fourier coefficients.
  • Prove why these coefficients give the closest fit within the span of the columns.
  • Build and verify the projection matrix for an orthogonal set of columns.
  • Recognize why the shortcut fails when the sampled columns are not orthogonal.

From Sampled Functions to Coefficients

Suppose a signal has been recorded at a finite list of times, and we want to describe its sampled values using familiar functions such as a constant, a sine, and a cosine. Each function becomes a column: evaluate it at every sample time, then place the results in a vector. If these columns are orthogonal, each coefficient can be found separately with a dot product. The calculation is a finite-data counterpart of the Fourier-series idea that a function can be described through its components along orthogonal sine and cosine functions.

Work over \(\mathbb{R}\). For columns \(\mathbf{u},\mathbf{v}\in\mathbb{R}^m\), their dot product is \(\mathbf{u}^{\top}\mathbf{v}\), and their squared length is \(\|\mathbf{u}\|^2=\mathbf{u}^{\top}\mathbf{u}\). The columns are orthogonal when their dot product is zero. A data vector \(\mathbf{y}\in\mathbb{R}^m\) records one value at each of the \(m\) sample times. A model using columns \(\mathbf{q}_1,\dots,\mathbf{q}_p\) has fitted vector \(c_1\mathbf{q}_1+\cdots+c_p\mathbf{q}_p\), where the real numbers \(c_j\) are its coefficients.

Definition: Let \(\mathbf{q}_1,\dots,\mathbf{q}_p\in\mathbb{R}^m\) be nonzero, pairwise orthogonal columns. The orthogonal coefficient of data \(\mathbf{y}\) along column \(\mathbf{q}_j\) is \(c_j=(\mathbf{q}_j^{\top}\mathbf{y})/(\mathbf{q}_j^{\top}\mathbf{q}_j)\). The corresponding fitted vector is \(\widehat{\mathbf{y}}=\sum_{j=1}^{p}c_j\mathbf{q}_j\), which lies in \(\operatorname{span}\{\mathbf{q}_1,\dots,\mathbf{q}_p\}\).

The denominator matters unless the column has squared length \(1\). A column with a larger length can have a larger dot product with the data even when its coefficient is unchanged. Dividing by its squared length corrects for that scaling. In Fourier-series language, a dot product is replaced by a finite sum over sampled times, while the denominator accounts for the sampled function’s length. The exact coefficients depend on which times were sampled and which columns were included; they need not equal coefficients obtained from a continuous function or a different sampling scheme.

A Four-Point Sine-and-Cosine Grid

Take four equally spaced sample times \(t=0,\tfrac14,\tfrac12,\tfrac34\), and evaluate the constant function, \(\cos(2\pi t)\), and \(\sin(2\pi t)\). Their sampled columns are

$$ \mathbf{u}=\begin{bmatrix}1\\1\\1\\1\end{bmatrix}, \qquad \mathbf{c}=\begin{bmatrix}1\\0\\-1\\0\end{bmatrix}, \qquad \mathbf{s}=\begin{bmatrix}0\\1\\0\\-1\end{bmatrix}. $$

Direct dot products give \(\mathbf{u}^{\top}\mathbf{c}=0\), \(\mathbf{u}^{\top}\mathbf{s}=0\), and \(\mathbf{c}^{\top}\mathbf{s}=0\). Their squared lengths are \(\mathbf{u}^{\top}\mathbf{u}=4\), \(\mathbf{c}^{\top}\mathbf{c}=2\), and \(\mathbf{s}^{\top}\mathbf{s}=2\). Thus these three columns meet the definition, but they are not all unit length. The constant coefficient is an average over the four entries; the sine and cosine coefficients have denominator \(2\), not \(4\).

Worked Example: Constant, Cosine, and Sine Coefficients

For the data \(\mathbf{y}=\begin{bmatrix}5&2&1&0\end{bmatrix}^{\top}\), compute its coefficients along \(\mathbf{u},\mathbf{c},\mathbf{s}\) and check the residual.

First take the three dot products and divide by the matching squared lengths:

$$ c_{\mathbf{u}}=\frac{\mathbf{u}^{\top}\mathbf{y}}{4} =\frac{5+2+1+0}{4}=2, \qquad c_{\mathbf{c}}=\frac{\mathbf{c}^{\top}\mathbf{y}}{2} =\frac{5-1}{2}=2, \qquad c_{\mathbf{s}}=\frac{\mathbf{s}^{\top}\mathbf{y}}{2} =\frac{2-0}{2}=1. $$

The fitted data are \(2\mathbf{u}+2\mathbf{c}+\mathbf{s}\). Entry by entry, this is \(\begin{bmatrix}2+2+0&2+0+1&2-2+0&2+0-1\end{bmatrix}^{\top}=\begin{bmatrix}4&3&0&1\end{bmatrix}^{\top}\). Subtracting gives the residual \(\mathbf{r}=\mathbf{y}-\widehat{\mathbf{y}}=\begin{bmatrix}1&-1&1&-1\end{bmatrix}^{\top}\).

Check: \(\mathbf{u}^{\top}\mathbf{r}=1-1+1-1=0\), \(\mathbf{c}^{\top}\mathbf{r}=1-1=0\), and \(\mathbf{s}^{\top}\mathbf{r}=-1+1=0\). The residual is orthogonal to every included column, as a projection residual should be.

This calculation makes the Fourier analogy concrete: the constant, cosine, and sine columns each receive a coefficient measuring the data’s component in that direction. The fitted vector uses only those components. Any part of the data perpendicular to all three columns remains in the residual.

Why the Formula Gives the Closest Fit

Theorem: Suppose \(\mathbf{q}_1,\dots,\mathbf{q}_p\) are nonzero, pairwise orthogonal columns in \(\mathbb{R}^m\), and let \(\mathbf{y}\in\mathbb{R}^m\). The coefficients \(c_j=(\mathbf{q}_j^{\top}\mathbf{y})/(\mathbf{q}_j^{\top}\mathbf{q}_j)\) give the unique vector \(\widehat{\mathbf{y}}=\sum_{j=1}^{p}c_j\mathbf{q}_j\) in their span that minimizes the squared distance \(\|\mathbf{y}-\mathbf{z}\|^2\) over all \(\mathbf{z}\) in that span. Its residual is orthogonal to each \(\mathbf{q}_j\).

Proof. Set \(\mathbf{r}=\mathbf{y}-\widehat{\mathbf{y}}\). For each \(k\), expand its dot product with \(\mathbf{q}_k\):

$$ \mathbf{q}_k^{\top}\mathbf{r} =\mathbf{q}_k^{\top}\mathbf{y} -\sum_{j=1}^{p}c_j\mathbf{q}_k^{\top}\mathbf{q}_j =\mathbf{q}_k^{\top}\mathbf{y} -c_k\mathbf{q}_k^{\top}\mathbf{q}_k =0. $$

The second equality uses pairwise orthogonality to remove all terms with \(j\ne k\); the last uses the coefficient formula. Now take any other \(\mathbf{z}\) in the span. It has the form \(\mathbf{z}=\sum_{j=1}^{p}d_j\mathbf{q}_j\) for some scalars \(d_j\). Then \(\mathbf{y}-\mathbf{z}=\mathbf{r}+\sum_{j=1}^{p}(c_j-d_j)\mathbf{q}_j\). The residual is orthogonal to each column, so it is orthogonal to their linear combination. Expanding the squared length therefore gives

$$ \|\mathbf{y}-\mathbf{z}\|^2 =\|\mathbf{r}\|^2+ \left\|\sum_{j=1}^{p}(c_j-d_j)\mathbf{q}_j\right\|^2 =\|\mathbf{r}\|^2+\sum_{j=1}^{p}(c_j-d_j)^2\|\mathbf{q}_j\|^2 \ge \|\mathbf{r}\|^2. $$

Each \(\|\mathbf{q}_j\|^2\) is positive because \(\mathbf{q}_j\ne\mathbf{0}\). Equality holds only if every \(c_j-d_j=0\), so the minimizing coefficient list is unique. Thus \(\widehat{\mathbf{y}}\) is the unique closest vector in the span, and its residual is orthogonal to each column. \(\square\)

This proof explains why the coefficient formula is more than a convenient calculation. Orthogonality separates the squared error into a residual part and a nonnegative part measuring how far an alternative coefficient list moves from the formula’s coefficients. No other choice can improve the fit.

Reading the Coefficients and the Projection Matrix

Worked Example: Fitting Only the Sine and Cosine Components

Use the same four sample times, but fit only sine and cosine to \(\mathbf{y}=\begin{bmatrix}3&1&-1&-3\end{bmatrix}^{\top}\). The constant column is deliberately excluded, so the fitted vector must lie in \(\operatorname{span}\{\mathbf{c},\mathbf{s}\}\).

The coefficients are \(c_{\mathbf{c}}=(3+1)/2=2\) and \(c_{\mathbf{s}}=(1+3)/2=2\), since \(\mathbf{c}^{\top}\mathbf{y}=3+1=4\) and \(\mathbf{s}^{\top}\mathbf{y}=1+3=4\). Hence \(\widehat{\mathbf{y}}=2\mathbf{c}+2\mathbf{s}=\begin{bmatrix}2&2&-2&-2\end{bmatrix}^{\top}\). The residual is \(\begin{bmatrix}1&-1&1&-1\end{bmatrix}^{\top}\).

Check: \(\mathbf{c}^{\top}\mathbf{r}=1-1=0\) and \(\mathbf{s}^{\top}\mathbf{r}=-1+1=0\). The fit is exact within the specified two-column model: it uses no constant component. Adding a constant column would change the model space and could change the fitted vector.

For a matrix description, place the orthogonal columns into \(\mathbf{Q}=\begin{bmatrix}\mathbf{q}_1&\cdots&\mathbf{q}_p\end{bmatrix}\), and let \(\mathbf{D}\) be the diagonal matrix whose \(j\)th diagonal entry is \(\mathbf{q}_j^{\top}\mathbf{q}_j\). The coefficient vector is \(\mathbf{D}^{-1}\mathbf{Q}^{\top}\mathbf{y}\), and the fitted vector is \(\mathbf{P}\mathbf{y}\), where \(\mathbf{P}=\mathbf{Q}\mathbf{D}^{-1}\mathbf{Q}^{\top}\). The inverse exists because every diagonal entry of \(\mathbf{D}\) is positive.

Result: For nonzero pairwise orthogonal columns, \(\mathbf{P}=\mathbf{Q}\mathbf{D}^{-1}\mathbf{Q}^{\top}\) maps any data vector to its orthogonal projection onto the column span. Moreover, \(\mathbf{P}^{\top}=\mathbf{P}\) and \(\mathbf{P}^2=\mathbf{P}\).

Proof. By the coefficient formula, \(\mathbf{P}\mathbf{y}=\mathbf{Q}\mathbf{D}^{-1}\mathbf{Q}^{\top}\mathbf{y}=\sum_j(\mathbf{q}_j^{\top}\mathbf{y})/(\mathbf{q}_j^{\top}\mathbf{q}_j)\,\mathbf{q}_j\). The theorem just proved shows this is the projection. Since \(\mathbf{D}^{-1}\) is diagonal, it is symmetric; thus \(\mathbf{P}^{\top}=\mathbf{Q}\mathbf{D}^{-1}\mathbf{Q}^{\top}=\mathbf{P}\). Orthogonality gives \(\mathbf{Q}^{\top}\mathbf{Q}=\mathbf{D}\), so

$$ \mathbf{P}^2 =\mathbf{Q}\mathbf{D}^{-1}\mathbf{Q}^{\top} \mathbf{Q}\mathbf{D}^{-1}\mathbf{Q}^{\top} =\mathbf{Q}\mathbf{D}^{-1}\mathbf{D}\mathbf{D}^{-1}\mathbf{Q}^{\top} =\mathbf{P}. $$

Therefore applying \(\mathbf{P}\) twice gives the same result as applying it once. The first application has already placed the vector in the column span, so a second projection does not change it. \(\square\)

Worked Example: Including a Higher-Frequency Sampled Column

On the four-point grid, add the column \(\mathbf{h}=\begin{bmatrix}1&-1&1&-1\end{bmatrix}^{\top}\), the samples of \(\cos(4\pi t)\). It is orthogonal to \(\mathbf{u},\mathbf{c},\mathbf{s}\): the dot products are \(1-1+1-1=0\), \(1-1=0\), and \(-1+1=0\), respectively. Its squared length is \(4\).

For \(\mathbf{y}=\begin{bmatrix}4&0&2&2\end{bmatrix}^{\top}\), the four coefficients are

$$ c_{\mathbf{u}}=\frac{4+0+2+2}{4}=2,\quad c_{\mathbf{c}}=\frac{4-2}{2}=1,\quad c_{\mathbf{s}}=\frac{0-2}{2}=-1,\quad c_{\mathbf{h}}=\frac{4+2-2}{4}=1. $$

Thus \(\widehat{\mathbf{y}}=2\mathbf{u}+\mathbf{c}-\mathbf{s}+\mathbf{h}\). Its four entries are \(2+1+0+1=4\), \(2+0-1-1=0\), \(2-1+0+1=2\), and \(2+0+1-1=2\). Therefore \(\widehat{\mathbf{y}}=\mathbf{y}\), with residual \(\mathbf{0}\).

Check: Substitution into the coefficient formula gives the four dot products \(8,2,-2,4\), divided by squared lengths \(4,2,2,4\), respectively. These reproduce \(2,1,-1,1\), and the displayed combination reconstructs every data entry.

Common Pitfall: Forgetting the Column Length

For the first example, the dot product of the constant column with the data is \(\mathbf{u}^{\top}\mathbf{y}=8\). A tempting but incorrect calculation is to call \(8\) the constant coefficient. That would contribute \(8\mathbf{u}\), whose entries are all \(8\); it is not the projection of the data onto the constant column. The correct coefficient is \(8/(\mathbf{u}^{\top}\mathbf{u})=8/4=2\), so the constant component is \(2\mathbf{u}\). The denominator is essential because the sampled constant column has squared length \(4\), not \(1\).

A second caution is that the shortcut requires orthogonal columns. If sampled sine and cosine columns are not orthogonal on the chosen sample times, the separate dot-product formula does not generally give the closest fit. In that case, the columns interact in the coefficient equations, and the orthogonal formula cannot be used as though their cross-products were zero. Check the sampled dot products before applying it. Also check that no included column is zero: its squared length would be zero, making the formula undefined.

Orthogonal sampled columns are useful because they make coefficient interpretation direct: each coefficient records one component of the data, adjusted for the column’s sampled length. The projection viewpoint also makes the residual meaningful: it contains exactly the part perpendicular to the model columns. For periodic data, this gives a finite-sample analogue of Fourier analysis while keeping the computation grounded in vectors, dot products, and the actual observations.

Check Your Understanding

Use the coefficient formula and, where requested, verify the fit by substituting it back into the sampled columns.

  1. For \(\mathbf{u}=\begin{bmatrix}1&1&1&1\end{bmatrix}^{\top}\) and \(\mathbf{y}=\begin{bmatrix}2&4&0&2\end{bmatrix}^{\top}\), find the coefficient along \(\mathbf{u}\).
  2. On the four-point grid, compute the coefficient of \(\mathbf{y}=\begin{bmatrix}1&3&-1&-3\end{bmatrix}^{\top}\) along \(\mathbf{s}\).
  3. Explain why a coefficient along \(\mathbf{c}\) has denominator \(2\), while a coefficient along \(\mathbf{u}\) has denominator \(4\).
  4. For pairwise orthogonal nonzero columns, why is the coefficient list giving the closest fit unique?
  5. What must be checked before using separate dot products to compute coefficients from sampled sine and cosine columns?

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon