Skip to main content
Logo image

Coordinated Linear Algebra

Section 10.8 Extra Topic: Curve Fitting

We know that two points determine a line. Do you know how many points determine a quadratic function of the form \(f(x)=ax^2+bx+c\text{?}\) Given any number of points in the plane, is it always possible to find a polynomial function whose graph contains every one of the given points? To address these questions we will start with an alternative way of finding an equation of a line.

Exploration 10.8.1.

Consider two points \(A(-3, 2)\) and \(B(1,-2)\text{.}\) We will find a function \(f\) whose graph is a line that passes through these points. We know that \(f(x)=ax+b\) for some constants \(a\) and \(b\text{.}\) Because the graph of \(f\) passes through \(A\) and \(B\text{,}\) we must have the following:
\begin{equation*} \begin{matrix} f(-3)\amp =\amp a(-3)\amp +\amp b\amp =\amp 2\\ f(1)\amp =\amp a(1)\amp +\amp b\amp =\amp -2 \end{matrix} \end{equation*}
To solve for \(a\) and \(b\text{,}\) we need to solve the following matrix equation:
\begin{equation*} \begin{bmatrix}-3 \amp 1\\1 \amp 1\end{bmatrix}\begin{bmatrix}a\\b\end{bmatrix}=\begin{bmatrix}2\\-2\end{bmatrix}. \end{equation*}
Solving the equation, we find that \(a=-1\) and \(b=-1\text{.}\) This gives us:
\begin{equation*} f(x)=-x-1. \end{equation*}
The GeoGebra interactive below shows two points \(A\) and \(B\text{,}\) together with the matrix equation that produces function coefficients for the function whose graph passes through \(A\) and \(B\text{.}\) Drag the points around the plane to see how the matrix equation changes.
Figure 10.8.1.
From a purely formal standpoint, we observe that the matrix equation has the form:
\begin{equation*} \begin{matrix}\text{point }A\rightarrow\\\text{point }B\rightarrow\end{matrix}\begin{bmatrix}x\text{-coordinate} \amp 1\\x\text{-coordinate} \amp 1\end{bmatrix}\begin{bmatrix}a\\b\end{bmatrix}=\begin{bmatrix}y\text{-coordinate}\\y\text{-coordinate}\end{bmatrix}. \end{equation*}
where each row corresponds to one point.
Now we are ready to move to quadratic, and higher degree polynomial functions. Linear function in Exploration 10.8.1 had two unknown coefficients that we needed to find in order to determine the function. Two points gave us a system of two equations and two unknowns.
A quadratic polynomial function, whose graph is a parabola, is given by:
\begin{equation*} f(x)=ax^2+bx+c \end{equation*}
Three unknown coefficients will require three points to determine them.

Exploration 10.8.2.

We will find a quadratic function of the form \(f(x)=ax^2+bx+c\) whose graph passes through
\begin{equation*} A(-2,2), \ B(0, -1) \text{ and } C(1, 5). \end{equation*}
To do this, we need to find coefficients \(a\text{,}\) \(b\) and \(c\) such that
\begin{equation*} \begin{matrix}f(-2)\amp =\amp a(-2)^2\amp +\amp b(-2)\amp +\amp c\amp =\amp 2\\f(0)\amp =\amp a(0)^2\amp +\amp b(0)\amp +\amp c\amp =\amp -1\\f(1)\amp =\amp a(1)^2\amp +\amp b(1)\amp +\amp c\amp =\amp 5\end{matrix} \end{equation*}
The following GeoGebra interactive shows points \(A\text{,}\) \(B\text{,}\) and \(C\text{,}\) together with the matrix equation, and its solution.
Figure 10.8.2.
Drag the points around the plane to observe changes in the coefficient matrix. Think geometrically to find locations of \(A\text{,}\) \(B\) and \(C\) such that
  • \(a=b=0\text{;}\) \(c\neq 0\text{.}\)
  • \(a=0\text{;}\) \(b, c\neq 0\text{.}\)
Observe the structure of the matrix equation.
\begin{equation*} \begin{matrix}\text{point }A\rightarrow\\\text{point }B\rightarrow\\\text{point }C\rightarrow\end{matrix}\begin{bmatrix}(x\text{-coordinate})^2\amp x\text{-coordinate} \amp 1\\(x\text{-coordinate})^2\amp x\text{-coordinate} \amp 1\\(x\text{-coordinate})^2\amp x\text{-coordinate} \amp 1\end{bmatrix}\begin{bmatrix}a\\b\\c\end{bmatrix}=\begin{bmatrix}y\text{-coordinate}\\y\text{-coordinate}\\y\text{-coordinate}\end{bmatrix} \end{equation*}
In general (provided that no one point lies directly above another), given \(n\) points, we can always find an \((n-1)\)-degree polynomial function whose graph contains every one of the given points. To find such a polynomial function, given by \(f(x)=a_{n-1}x^{n-1}+\dots +a_1x+a_0\text{,}\) we need to solve a system of \(n\) equations with \(n\) unknowns which translates into the following matrix equation.
\begin{equation} \begin{bmatrix}\vdots\amp \vdots \amp \vdots \amp \vdots\\(x\text{-coordinate})^{n-1}\amp \dots \amp x\text{-coordinate} \amp 1\\\vdots\amp \vdots \amp \vdots \amp \vdots\end{bmatrix}\begin{bmatrix}a_{n-1}\\\vdots\\a_1\\a_0\end{bmatrix}=\begin{bmatrix}\vdots\\y\text{-coordinate}\\\vdots\end{bmatrix}.\tag{10.8.1} \end{equation}
In Exercise 10.8.2.3 and Exercise 10.8.2.4 you will show that the matrix equation in (10.8.1) has a unique solution if and only if no two of the given points share an \(x\)-coordinate.

Subsection 10.8.1 On the Dangers of Overfitting

It is exciting to know that we can fit a function to a set of data points, but before we get carried away fitting a 299-degree polynomial function to 300 points, let’s consider the following situation. In the GeoGebra interactive below, you can see that points \(A\) - \(F\) form a somewhat linear pattern.
A linear model can be used to describe these points. Click on the ``Display linear model" check-box to see the trend line. (You learned how to find such models when discovering Least-Squares Approximation). You can see that even though the line does not pass through any of the given points, it fits the overall pattern of the points and can be used to estimate the \(y\)-coordinates of other points whose \(x\)-coordinates fall within the limits of the scatter plot.
It might be tempting to think that we can find a better model by finding a \(5^{th}\)-degree polynomial function whose graph contains every one of the six points. Click on the ``Display 5th degree poly model" check-box to see the alternative model. Can this model be successfully used to make predictions? Try moving individual points around to see how their placement affects the line and the curve.
Figure 10.8.3. A larger version of this activity is available here
 1 
geogebra.org
.
Any modeling process which insists on fitting the existing data points exactly, at the risk of failing to predict future observations, is referred to as overfitting. While sometimes it is beneficial to have a curve that passes through specific points, more often it is the trend, not the individual instances, that we try to capture. We will return to this topic when discussing least-squares approximations.

Exercises 10.8.2 Exercises

Exercise Group.

In each case, find a polynomial function of an appropriate degree that passes through the given points. You are encourage to plot the graph of \(f\) in Desmos.
1.
\begin{equation*} (-3,0), \ (2, -2), \ (-1,1). \end{equation*}
Answer.
\begin{equation*} f(x)=-0.3x^2-0.7x+0.6. \end{equation*}
2.
\begin{equation*} (0,4), \ (-2, 2), \ (-1,1),\ (0.5, 1). \end{equation*}
Answer.
\begin{equation*} g(x)=-3.2x^3-7.6x^2-1.4x+4. \end{equation*}

3.

    Two GeoGebra screenshots are shown below:
    In the first screenshot, points \(A\) and \(B\) coincide. In the second screenshot, point \(A\) is located directly above point \(B\text{.}\) In both cases, GeoGebra failed to produce a linear function whose graph passes through \(A\) and \(B\text{.}\)
    Based on what you know about functions and geometry, explain why the process fails for these two examples. How do your observations correspond to what happens from an algebraic standpoint?
  • Both systems are inconsistent.
  • The first system is inconsistent, the second has infinitely many solutions.
  • Both systems have infinitely many solutions.
  • The first system has infinitely many solutions, the second system is inconsistent.

4.

Prove that (10.8.1) has a unique solution if and only if no two given points share an \(x\)-coordinate. Under what circumstances is a solution not unique? Under what circumstances does a solution not exist?
Hint.
Show that the rows of the matrix are linearly independent if and only if no two given points share an \(x\)-coordinate.