Skip to main content
Mathematics LibreTexts

2.3: Polynomial Fitting

  • Page ID
    14756
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \def\d{\displaystyle}\)
    \( \newcommand{\f}[1]{\mathfrak #1}\)
    \( \newcommand{\s}[1]{\mathscr #1}\)
    \( \def\N{\mathbb N}\)
    \( \def\B{\mathbf{B}}\)
    \( \def\circleA{(-.5,0) circle (1)}\)
    \( \def\Z{\mathbb Z}\)
    \( \def\circleAlabel{(-1.5,.6) node[above]{$A$}}\)
    \( \def\Q{\mathbb Q}\)
    \( \def\circleB{(.5,0) circle (1)}\)
    \( \def\R{\mathbb R}\)
    \( \def\circleBlabel{(1.5,.6) node[above]{$B$}}\)
    \( \def\C{\mathbb C}\)
    \( \def\circleC{(0,-1) circle (1)}\)
    \( \def\F{\mathbb F}\)
    \( \def\circleClabel{(.5,-2) node[right]{$C$}}\)
    \( \def\A{\mathbb A}\)
    \( \def\twosetbox{(-2,-1.5) rectangle (2,1.5)}\)
    \( \def\X{\mathbb X}\)
    \( \def\threesetbox{(-2,-2.5) rectangle (2,1.5)}\)
    \( \def\E{\mathbb E}\)
    \( \def\O{\mathbb O}\)
    \( \def\U{\mathcal U}\)
    \( \def\pow{\mathcal P}\)
    \( \def\inv{^{-1}}\)
    \( \def\nrml{\triangleleft}\)
    \( \def\st{:}\)
    \( \def\~{\widetilde}\)
    \( \def\rem{\mathcal R}\)
    \( \def\sigalg{$\sigma$-algebra }\)
    \( \def\Gal{\mbox{Gal}}\)
    \( \def\iff{\leftrightarrow}\)
    \( \def\Iff{\Leftrightarrow}\)
    \( \def\land{\wedge}\)
    \( \def\And{\bigwedge}\)
    \( \def\entry{\entry}\)
    \( \def\AAnd{\d\bigwedge\mkern-18mu\bigwedge}\)
    \( \def\Vee{\bigvee}\)
    \( \def\VVee{\d\Vee\mkern-18mu\Vee}\)
    \( \def\imp{\rightarrow}\)
    \( \def\Imp{\Rightarrow}\)
    \( \def\Fi{\Leftarrow}\)
    \( \def\var{\mbox{var}}\)
    \( \def\Th{\mbox{Th}}\)
    \( \def\entry{\entry}\)
    \( \def\sat{\mbox{Sat}}\)
    \( \def\con{\mbox{Con}}\)
    \( \def\iffmodels{\bmodels\models}\)
    \( \def\dbland{\bigwedge \!\!\bigwedge}\)
    \( \def\dom{\mbox{dom}}\)
    \( \def\rng{\mbox{range}}\)
    \( \def\isom{\cong}\)
    \(\DeclareMathOperator{\wgt}{wgt}\)
    \( \newcommand{\vtx}[2]{node[fill,circle,inner sep=0pt, minimum size=4pt,label=#1:#2]{}}\)
    \( \newcommand{\va}[1]{\vtx{above}{#1}}\)
    \( \newcommand{\vb}[1]{\vtx{below}{#1}}\)
    \( \newcommand{\vr}[1]{\vtx{right}{#1}}\)
    \( \newcommand{\vl}[1]{\vtx{left}{#1}}\)
    \( \renewcommand{\v}{\vtx{above}{}}\)
    \( \def\circleA{(-.5,0) circle (1)}\)
    \( \def\circleAlabel{(-1.5,.6) node[above]{$A$}}\)
    \( \def\circleB{(.5,0) circle (1)}\)
    \( \def\circleBlabel{(1.5,.6) node[above]{$B$}}\)
    \( \def\circleC{(0,-1) circle (1)}\)
    \( \def\circleClabel{(.5,-2) node[right]{$C$}}\)
    \( \def\twosetbox{(-2,-1.4) rectangle (2,1.4)}\)
    \( \def\threesetbox{(-2.5,-2.4) rectangle (2.5,1.4)}\)
    \( \def\ansfilename{practice-answers}\)
    \( \def\shadowprops{ {fill=black!50,shadow xshift=0.5ex,shadow yshift=0.5ex,path fading={circle with fuzzy edge 10 percent}} }\)
    \( \renewcommand{\bar}{\overline}\)
    \( \newcommand{\card}[1]{\left| #1 \right|}\)
    \( \newcommand{\twoline}[2]{\begin{pmatrix}#1 \\ #2 \end{pmatrix}}\)
    \( \newcommand{\lt}{<}\)
    \( \newcommand{\gt}{>}\)
    \( \newcommand{\amp}{&}\)

    \( \newcommand{\hexbox}[3]{
      \def\x{-cos{30}*\r*#1+cos{30}*#2*\r*2}
      \def\y{-\r*#1-sin{30}*\r*#1}
      \draw (\x,\y) +(90:\r) -- +(30:\r) -- +(-30:\r) -- +(-90:\r) -- +(-150:\r) -- +(150:\r) -- cycle;
      \draw (\x,\y) node{#3};
    }\)

    \(\renewcommand{\bar}{\overline}\)
    \(\newcommand{\card}[1]{\left| #1 \right|}\)
    \(\newcommand{\twoline}[2]{\begin{pmatrix}#1 \\ #2 \end{pmatrix}}\)
    \(\newcommand{\lt}{<}\)
    \(\newcommand{\gt}{>}\)
    \(\newcommand{\amp}{&}\)

    Investigate!

    A standard \(8 \times 8\) chessboard contains 64 squares. Actually, this is just the number of unit squares. How many squares of all sizes are there on a chessboard? Start with smaller boards: \(1\times 1\text{,}\) \(2 \times 2\text{,}\) \(3\times 3\text{,}\) etc. Find a formula for the total number of squares in an \(n\times n\) board.

    So far we have seen methods for finding the closed formulas for arithmetic and geometric sequences. Since we know how to compute the sum of the first \(n\) terms of arithmetic and geometric sequences, we can compute the closed formulas for sequences which have an arithmetic (or geometric) sequence of differences between terms. But what if we consider a sequence which is the sum of the first \(n\) terms of a sequence which is itself the sum of an arithmetic sequence?

    Before we get too carried away, let's consider an example: How many squares (of all sizes) are there on a chessboard? A chessboard consists of \(64\) squares, but we also want to consider squares of longer side length. Even though we are only considering an \(8 \times 8\) board, there is already a lot to count. So instead, let us build a sequence: the first term will be the number of squares on a \(1 \times 1\) board, the second term will be the number of squares on a \(2 \times 2\) board, and so on. After a little thought, we arrive at the sequence

    \begin{equation*} 1,5,14,30, 55,\ldots \end{equation*}

    This sequence is not arithmetic (or geometric for that matter), but perhaps it's sequence of differences is. For differences we get

    \begin{equation*} 4, 9, 16, 25, \ldots \end{equation*}

    Not a huge surprise: one way to count the number of squares in a \(4 \times 4\) chessboard is to notice that there are \(16\) squares with side length 1, 9 with side length 2, 4 with side length 3 and 1 with side length 4. So the original sequence is just the sum of squares. Now this sequence of differences is not arithmetic since it's sequence of differences (the differences of the differences of the original sequence) is not constant. In fact, this sequence of second differences is

    \begin{equation*} 5, 7, 9, \ldots \end{equation*}

    which is an arithmetic sequence (with constant difference 2). Notice that our original sequence had third differences (that is, differences of differences of differences of the original) constant. We will call such a sequence \(\Delta^3\)-constant. The sequence \(1, 4, 9, 16, \ldots\) has second differences constant, so it will be a \(\Delta^2\)-constant sequence. In general, we will say a sequence is a \(\Delta^k\)-constant sequence if the \(k\)th differences are constant.

    Example \(\PageIndex{1}\)

    Which of the following sequences are \(\Delta^k\)-constant for some value of \(k\text{?}\)

    1. \(2, 3, 7, 14, 24, 37,\ldots\text{.}\)
    2. \(1, 8, 27, 64, 125, 216, \ldots\text{.}\)
    3. \(1,2,4,8,16,64,128,\ldots\text{.}\)
    Solution
    1. This is the sequence from Example 2.2.6, in which we found a closed formula by recognizing the sequence as the sequence of partial sums of an arithmetic sequence. Indeed, the sequence of first differences is \(1,4,7, 10, 13,\ldots\text{,}\) which itself has differences \(3,3,3,3,\ldots\text{.}\) Thus \(2, 3, 7, 14, 24, 37,\ldots\) is a \(\Delta^2\)-constant sequence.
    2. These are the perfect cubes. The sequence of first differences is \(7, 19, 37, 61, 91, \ldots\text{;}\) the sequence of second differences is \(12, 18, 24, 30,\ldots\text{;}\) the sequence of third differences is constant: \(6,6,6,\ldots\text{.}\) Thus the perfect cubes are a \(\Delta^3\)-constant sequence.
    3. If we take first differences we get \(1,2,4,8,16,\ldots\text{.}\) Wait, what? That's the sequence we started with. So taking second differences will give us the same sequence again. No matter how many times we repeat this we will always have the same sequence, which in particular means no finite number of differences will be constant. Thus this sequence is not \(\Delta^k\)-constant for any \(k\text{.}\)

    The \(\Delta^0\)-constant sequences are themselves constant, so a closed formula for them is easy to compute (it's just the constant). The \(\Delta^1\)-constant sequences are arithmetic and we have a method for finding closed formulas for them as well. Every \(\Delta^2\)-constant sequence is the sum of an arithmetic sequence so we can find formulas for these as well. But notice that the format of the closed formula for a \(\Delta^2\)-constant sequence is always quadratic. For example, the square numbers are \(\Delta^2\)-constant with closed formula \(a_n= n^2\text{.}\) The triangular numbers (also \(\Delta^2\)-constant) have closed formula \(a_n = \frac{n(n+1)}{2}\text{,}\) which when multiplied out gives you an \(n^2\) term as well. It appears that every time we increase the complexity of the sequence, that is, increase the number of differences before we get constants, we also increase the degree of the polynomial used for the closed formula. We go from constant to linear to quadratic. The sequence of differences between terms tells us something about the rate of growth of the sequence. If a sequence is growing at a constant rate, then the formula for the sequence will be linear. If the sequence is growing at a rate which itself is growing at a constant rate, then the formula is quadratic. You have seen this elsewhere: if a function has a constant second derivative (rate of change) then the function must be quadratic.

    This works in general:

    Finite Differences

    The closed formula for a sequence will be a degree \(k\) polynomial if and only if the sequence is \(\Delta^k\)-constant (i.e., the \(k\)th sequence of differences is constant).

    This tells us that the sequence of numbers of squares on a chessboard, \(1, 5, 14, 30, 55, \ldots\text{,}\) which we saw to be \(\Delta^3\)-constant, will have a cubic (degree 3 polynomial) for its closed formula.

    Now once we know what format the closed formula for a sequence will take, it is much easier to actually find the closed formula. In the case that the closed formula is a degree \(k\) polynomial, we just need \(k+1\) data points to “fit” the polynomial to the data.

    Example \(\PageIndex{2}\)

    Find a formula for the sequence \(3, 7, 14, 24,\ldots\text{.}\) Assume \(a_1 = 3\text{.}\)

    Solution

    First, check to see if the formula has constant differences at some level. The sequence of first differences is \(4, 7, 10, \ldots\) which is arithmetic, so the sequence of second differences is constant. The sequence is \(\Delta^2\)-constant, so the formula for \(a_n\) will be a degree 2 polynomial. That is, we know that for some constants \(a\text{,}\) \(b\text{,}\) and \(c\text{,}\)

    \begin{equation*} a_n = an^2 + bn + c. \end{equation*}

    Now to find \(a\text{,}\) \(b\text{,}\) and \(c\text{.}\) First, it would be nice to know what \(a_0\) is, since plugging in \(n = 0\) simplifies the above formula greatly. In this case, \(a_0 = 2\) (work backwards from the sequence of constant differences). Thus

    \begin{equation*} a_0 = 2 = a\cdot 0^2 + b \cdot 0 + c, \end{equation*}

    so \(c = 2\text{.}\) Now plug in \(n =1\) and \(n = 2\text{.}\) We get

    \begin{equation*} a_1 = 3 = a + b + 2 \end{equation*} \begin{equation*} a_2 = 7 = a4 + b 2 + 2. \end{equation*}

    At this point we have two (linear) equations and two unknowns, so we can solve the system for \(a\) and \(b\) (using substitution or elimination or even matrices). We find \(a = \frac{3}{2}\) and \(b = \frac{-1}{2}\text{,}\) so \(a_n = \frac{3}{2} n^2 - \frac{1}{2}n + 2\text{.}\)

    Example \(\PageIndex{3}\)

    Find a closed formula for the number of squares on an \(n \times n\) chessboard.

    Solution

    We have seen that the sequence \(1, 5, 14, 30, 55, \ldots\) is \(\Delta^3\)-constant, so we are looking for a degree 3 polynomial. That is,

    \begin{equation*} a_n = an^3 + bn^2 + cn + d. \end{equation*}

    We can find \(d\) if we know what \(a_0\) is. Working backwards from the third differences, we find \(a_0 = 0\) (unsurprisingly, since there are no squares on a \(0\times 0\) chessboard). Thus \(d = 0\text{.}\) Now plug in \(n = 1\text{,}\) \(n =2\text{,}\) and \(n =3\text{:}\)

    \begin{align*} 1 = & a + b + c\\ 5 = & 8a + 4b + 2c\\ 14 = & 27a + 9b + 3c. \end{align*}

    If we solve this system of equations we get \(a = \frac{1}{3}\text{,}\) \(b = \frac{1}{2}\) and \(c = \frac{1}{6}\text{.}\) Therefore the number of squares on an \(n \times n\) chessboard is \(a_n = \frac{1}{3}n^3 + \frac{1}{2}n^2 + \frac{1}{6}n\text{.}\)

    Note: Since the squares-on-a-chessboard problem is really asking for the sum of squares, we now have a nice formula for \(\d\sum_{k=1}^n k^2\text{.}\)

    Not all sequences will have polynomials as their closed formula. We can use the theory of finite differences to identify these.

    Example \(\PageIndex{4}\)

    Determine whether the following sequences can be described by a polynomial, and if so, of what degree.

    1. \(1, 2, 4, 8, 16, \ldots\)
    2. \(0, 7, 50, 183, 484, 1055, \ldots\)
    3. \(1,1,2,3,5,8,13,\ldots\)
    Solution
    1. As we saw in Example 2.3.1, this sequence is not \(\Delta^k\)-constant for any \(k\text{.}\) Therefore the closed formula for the sequence is not a polynomial. In fact, we know the closed formula is \(a_n = 2^n\text{,}\) which grows faster than any polynomial (so is not a polynomial).
    2. The sequence of first differences is \(7, 43, 133, 301, 571,\ldots\text{.}\) The second differences are: \(36, 90, 168, 270,\ldots\text{.}\) Third difference: \(54, 78, 102,\ldots\text{.}\) Fourth differences: \(24, 24, \ldots\text{.}\) As far as we can tell, this sequence of differences is constant so the sequence is \(\Delta^4\)-constant and as such the closed formula is a degree 4 polynomial.
    3. This is the Fibonacci sequence. The sequence of first differences is \(0, 1, 1, 2, 3, 5, 8, \ldots\text{,}\) the second differences are \(1, 0, 1, 1, 2, 3, 5\ldots\text{.}\) We notice that after the first few terms, we get the original sequence back. So there will never be constant differences, so the closed formula for the Fibonacci sequence is not a polynomial.

    This page titled 2.3: Polynomial Fitting is shared under a CC BY-SA license and was authored, remixed, and/or curated by Oscar Levin.

    • Was this article helpful?