Preface
Goal: Connect the dots perfectly with interpolation.
Curve fitting is not the only target that you want to achieve. We might just want to connect the dots perfectly. This is called interpolation.
Unlike curve fitting, interpolation require the curve to pass through all the given data points. We can use polynomial method to connect a few data points. This method use minimal required point to calculate the equation for example:
- Two points for linear equation.
- Three points for quadratic equation.
- Four points for cubic equation.
There is even an easier way to obtain linear equation. It is by calculating the slope.
Please note that when conducting interpolation in practical applications, curve fitting isn’t the sole method available. There are also the option to utilize multiple straight lines, connecting points from one to another, without necessitating of curve fitting at all.
Worksheet Source
Playsheet Artefact
The worksheet provided is ready to used for daily problem solving.
This workbook containing multiple sheet, so you can choose any method that suit for you.
The Excel file is available, so you can have fun, modify as you want.
1: Straight Line from Two Points
Calculating Slope
If all you need is just conneting two point, you should use simple method instead of the complex one. Stay away from polynomial method, and just use this slope equation.
The Math Behind
The equation of linear trend for staright line is simple.
To calculate the slope you can just measure the difference for both y and x.
For two points, the slope become y2-y1
, and x2-x1
.
Then we can finally get the a
variable.
The variable names is commonly named as:
m
: slope, anda
: intercept.
The notation can be different from book to book. But they have the same meaning. Such this below example:
You might even see the cryptic form as below, for curve fitting with many samples data.
They are all serve simple straight lines.
Getting Coefficient
Supposed you have two pairs of point
p1
= (11, 49), andp2
= (12, 53)
You can get the coefficient as
m
= 5, anda
= 4
Predicting Values
Now you can predict the interpolation value for example [0, 5, 12]
This will get this pairs of point:
- (
x
= 0,y
= 5), - (
x
= 5,y
= 25), - (
x
= 12,y
= 53),
And so on.
Polynomial Interpolation: Linear
Minimum Two Points
Matrix Equation
Getting unknown Coefficient value
Supposed we want to connect two points.
A system of linear equations can be represented as a matrix equation
This matrix can be represented as variable below:
We are going to solve the formula above using this equation
You can use spreadsheet using minverse
formula.
And solve this matrix equation and get below coefficient result:
The detail is:
With coefficient above we can write the linear equation as below:
Worksheet
Getting unknown Y-Value
With spreadsheet, we can write down the equation, as below to get the coefficient:
The formula is something like below:
=MMULT(MINVERSE(E9:F10);J9:J10)
Now we can easily get the predicted value using interpolation above.
Polynomial Interpolation: Quadratic
Minimum Three Points
With the same method as linear equation, we can do the the quadratic equation.
Matrix Equation
Getting unknown Coefficient value
Supposed we want to connect three points.
A system of quadratic equations can also be represented as a matrix equation
This matrix also can be represented as variable. Again, we are going to solve the formula above using this equation
You can use spreadsheet using minverse
formula.
And solve this matrix equation and get below coefficient result:
With coefficient above we can write the linear equation as below:
Worksheet
Getting unknown Y-Value
With spreadsheet, we can write down the equation, as below to get the coefficient:
The formula is something like below:
=MMULT(MINVERSE(E9:G11);K9:K11)
Now we can easily get the predicted value using interpolation above.
Polynomial Interpolation: Cubic
Minimum Four Points
With the same method as linear equation and quadratic equation, we can do the the cubic equation.
Matrix Equation
Getting unknown Coefficient value
Supposed we want to connect three points.
A system of cubic equations can be represented as a matrix equation
This matrix also can be represented as variable. Again, we are going to solve the formula above using this equation
You can still use spreadsheet using minverse
formula,
to solve this matrix equation and get below coefficient result:
With coefficient above we can write the linear equation as below:
Worksheet
Getting unknown Y-Value
With spreadsheet, we can write down the equation, as below to get the coefficient:
The formula is something like below:
=MMULT(MINVERSE(E9:H12);L9:L12)
Now we can easily get the predicted value using interpolation above.
What’s Our Next Endeavor 🤔?
Polynomial curve fitting using the same basic equation as above,
but using more data. In real life most data are dispersed,
and do not connect perfectly between points.
All we need to do is adjust the equation a bit,
and also adjust the previous polyfit
into manual matrix calculation.
For a hands-on experience and a deeper grasp of these concepts, let’s explore further in [ Trend - Polynomial Algebra ].