This post is part of my Game Math Series.

### Polynomials

A polynomial is an expression consisting of linear combination of products of variables raised to non-negative integer powers. In this post, I will specifically focus on polynomials of a single variable, namely polynomials of the form:

The polynomial above are said to have __degree__ if the coefficient is non-zero.

### Polynomial Curves

We can create curves with polynomials by using the equation .

For instance, we can create a parabola with :

Or a down-facing parabola shifted from the origin: .

### Approximating Curves with Polynomial Curves

For games, some mathematical functions are so expensive that it is beneficial to approximate them using polynomial curves. In general, the higher the degree of polynomial we use to approximate the function, the better the approximation will be.

So we have a function that we want to approximate, , and a polynomial of degree , . We need to find all the coefficients of the polynomial. That gives us unknowns, which means we will need equations to obtain all the coefficients.

How do we get the equations? It depends on how you want the curve to match the function . If we want the curve to perfectly match the curve at and , then we get these two equations:

Sometimes matching the points on the function curve is not enough. We might want to also match the slopes of the curve at certain points. Say we also want to match the function curve’s slopes at and , then we get another two equations:

Four equations means four __conditions__ for our approximation. In order to satisfy conditions when approximating a function with a polynomial, we need the polynomial to have a degree of at least , giving us coefficients.

In this case, we need a cubic polynomial, .

Let’s pick the exponential function, to be the function we want to approximate with . Using the four equations above, we can solve for the four coefficients (, , , and ).

After removing all the noise, we get:

We can then solve this system of equations and obtain the coefficients:

And here’s the polynomial that we’ll use to approximate :

Let’s see how close we are by plotting and on top of each other.

The blue curve is the exponential curve, and the red curve is the polynomial approximation. They are almost identical between and . They are exactly the same up to the first-order derivative at and , because these are the four conditions we used to come up with the polynomial.

The approximating polynomial will be accurate around the points you choose for the conditions (in this example, and ). If you’d like the polynomial curve to match at other points of the curve, then you’ll need a polynomial of higher degree and more equations to solve for the coefficients of the polynomial.

### Approximation with Polynomial Curves

This is how you would approximate a function with polynomial curves. In general, the more accurate you want the polynomial curve to be, the higher the degree of the polynomial will be, and the more coefficients you’ll have to solve for.