# How to write a possibly cubic equation given a set of coordinates

Given a specific set of coordinates, I'm trying to write an equation that will describe their curve.

By graphing the coordinates, I believe it should be a cubic equation. But there is only one root at $$(0,0)$$.

The coordinates are as follows: $$(0,0)$$, $$(2.1258,15)$$, $$(4.5809,30)$$, $$(7.8878,45)$$, $$(13.6083,60)$$, $$(27.2268,75)$$, $$(57.1741,85)$$, $$(90,90)$$, $$(121.4014,95)$$, $$(152.3215,105)$$, $$(166.4417,120)$$, $$(177.8625,165)$$, $$(175.4013,150)$$, $$(180,180)$$

I have been reading and watching video tutorials about cubic equations but they're all either given the equation or given multiple roots.

The closest equation I've been able to write (guess, really) is as follows, but it doesn't quite follow the curve. $$p(x)=0.0001(x-90)^3+90$$

I am not looking for you to tell me the equation, I want to learn how to write them. Any help is greatly appreciated.

Edit below:

Perhaps it would be relevant to mention that there are limits to the Y value, when $$x<90$$ then $$y<90$$, the opposite is also true. Not sure if this changes anything, though.

• Have you tried Lagrange interpolation? May 21, 2020 at 19:19
• I have not, I will explore this subject, thank you. May 21, 2020 at 19:29
• Are those points known to originate from a cubic equation, or are they only "approximately cubic" and you want to find a "best fit" for those points? May 21, 2020 at 19:37
• "Approximately cubic", I just need a "best fit". May 21, 2020 at 20:15

The least square fitted polynomials below are produced by (essentially) the matrix computation described at polynomial regression.

This data is not actually produced by a cubic. The procedure in Allain Remillard's answer can be used to show this. The cubic of best fit (least summed square errors) is shown with the data:

$$11.8893 + 3.33669 x - 0.041162 x^2 + 0.000152843 x^3$$

The least squares fitted quintic gets closer. $$2.99379 + 6.11504 x - 0.173352 x^2 + 0.00225902 x^3 - 0.0000134475 x^4 + 2.98074*10^{-8} x^5$$

But the tiny coefficients and alternating signs (also present in the cubic), together with the shallow "wave" in the middle suggests we are on the threshold of (or have just passed) overfitting. It seems likely that the data do not follow any polynomial.

The Lagrange interpolating polynomial is guaranteed to pass through every point, but has degree $$13$$, so is very likely overfitted. (If there were a polynomial of lower degree that would pass through the points, cancellation in the product for finding the Lagrange polynomial would reduce the degree.) We expect to be overfitted, so we expect large deviations in the gaps between the data points.

You face a choice now. Do you allow more complicated models, hoping to find one that can produce your data, or do you settle for a simple model because it captures the features you know you want to capture? The answer to this question depends strongly on what you intend to do with the model fit, which is not in the scope of the Question as asked.

• This is a great answer, Mr. Towers, thank you very much. It seems I will need to research polynomial regression. I can produce more data points, but they always come with some degree of measuring error, so I want to learn how to generate such equations. In the end, I am looking for a close-enough equation (say, down to single decimal places). May 21, 2020 at 20:42
• @ReinhardMeier : I believe I have already brought into question the polynomial of degree $5$ and have been clear that the situation does not improve in higher degrees. Regarding Runge's phenomenon, this is usually associated with evenly spaced sample points -- with the densification of sample points at the ends of the interval, this phenomenon is suppressed in this data. May 21, 2020 at 21:01

Disclaimer I haven't tried it but it is too long for a comment.

If you want to test wether it is cubic or not, notice the following. There are three colinear point $$(0,0), (90,90)$$ and $$(180,180)$$.

If $$p(x)$$ is a cubic polynomial going thru all the points, then $$p(x)-x$$ is a cubic polynomial with roots at $$x=0$$, $$x=90$$ and $$x=180$$. Then $$p(x)-x=a(x-0)(x-90)(x-180)$$ So $$p(x)=a(x-0)(x-90)(x-180)+x$$ By trying it with an other point, you could find the value of $$a$$. Finally, test the other points to verify if it really was a cubic function.

A cubic polynomial $$p(x) = a_3x^3+a_2x^2+a_1x+a_0$$ has only four parameters you can adjust to fit the given points as well as possible. So in general it is unlikely to find a cubic polynomial that exactly interpolates all the given $$N$$ points, if $$N>4.$$

Therefore you have to choose a criterion that tells you how "good" your approximating polynomial actually is. There are different ways of measuring the deviation (lets call it $$D$$) from the set of points, i.e. the value you want to minimize. You could use the maximum distance: $$D = \max_{1\leq i\leq N} |p(x_i)-y_i|$$ You could also use the sum of the squares of the distances: $$D = \sum_{i=1}^N \left(p(x_i)-y_i\right)^2$$ as a measure for the deviation. This approach is also known as the method of least squares and has some advantages over other methods: The result is usually unique and easy to calculate. There are also some theoretical aspects that show that this sort approximation is the best one if the measurement errors in the original data set can be assumed to follow a normal distribution.

The first approach (maximum distance) results in a system of inequalities that must be solved using linear programming. So let us focus on the second approach, the method of least squares.

We have $$D(a_0, a_1, a_2, a_3) = \sum_{i=1}^N \left(a_3x_i^3+a_2x_i^2+a_1x_i+a_0-y_i\right)^2$$ In order to find the minimum of D, we differentiate this by $$a_0,$$ $$a_1,$$ $$a_2$$ and $$a_3$$ and set each of the partial derivatives to $$0.$$ This gives us a system of $$4$$ equations from which we can obtain the $$a_k.$$ In particular we get $$\begin{eqnarray} \frac{\partial D}{\partial a_0} &= & \sum_{i=1}^N 2 \left(a_3x_i^3+a_2x_i^2+a_1x_i+a_0-y_i\right) = 0 \\ \frac{\partial D}{\partial a_1} &= & \sum_{i=1}^N 2x_i \left(a_3x_i^3+a_2x_i^2+a_1x_i+a_0-y_i\right) = 0 \\ \frac{\partial D}{\partial a_2} &= & \sum_{i=1}^N 2x_i^2 \left(a_3x_i^3+a_2x_i^2+a_1x_i+a_0-y_i\right) = 0 \\ \frac{\partial D}{\partial a_3} &= & \sum_{i=1}^N 2x_i^3 \left(a_3x_i^3+a_2x_i^2+a_1x_i+a_0-y_i\right) = 0 \end{eqnarray}$$ such that you get the $$a_k$$ from the following system on linear equations $$\begin{pmatrix} N & \sum x_i & \sum x_i^2 & \sum x_i^3 \\ \sum x_i & \sum x_i^2 & \sum x_i^3 & \sum x_i^4 \\ \sum x_i^2 & \sum x_i^3 & \sum x_i^4 & \sum x_i^5 \\ \sum x_i^3 & \sum x_i^4 & \sum x_i^5 & \sum x_i^6 \end{pmatrix} \begin{pmatrix} a_0 \\ a_1 \\ a_2 \\ a_3 \end{pmatrix} = \begin{pmatrix} \sum y_i \\ \sum x_i y_i \\ \sum x_i^2 y_i \\ \sum x_i^3 y_i \end{pmatrix}$$