You are on page 1of 10

Lecture No.

5 - Numerical Solutions to CE Problems


Curve Fitting and Interpolations
Definitions:
Curve-fitting is finding a line or curve that best fits the general shape of the given data points, or
it is the process of constructing a curve, or mathematical function, that has the best fit to the
series of data points. Most commonly, one fits a function of the form y= f(x).
Fitting lines and polynomial functions to data points
The first degree polynomial equation
𝒚 = 𝒂𝒙 + 𝒃
is a line with slope a. A line will connect any two points, so a first degree polynomial equation is
an exact fit through any two points with distinct x coordinates.
If the order of the equation is increased to a second degree polynomial, the following
results:

𝒚 = 𝒂𝒙𝟐 + bx + c
This will exactly fit a simple curve to three points.
If the order of the equation is increased to a third degree polynomial, the following is
obtained:
𝒚 = 𝒂𝒙𝟑 + 𝒃𝒙𝟐 + cx + d
This will exactly fit four points.

See illustration below:

Polynomial curves fitting points generated with a


sine function. Red line is a first degree polynomial,
green line is second degree, orange line is third
degree and blue is fourth degree.
Interpolation is when you have two points of data and want to know what a value between the
two would be.
Linear Interpolation is a method of curve fitting using linear polynomials to construct new data
points within the range of a discrete set of known data points.

Given the two red points, the blue line is the linear interpolation
between the points, and the value y at x may be found by linear
interpolation.

Linear Interpolation between two known points


If the two known points are given by the coordinates ( 𝑥0 , 𝑦0 ) and ( 𝑥1 , 𝑦1 ) , the linear
nterpolant is the straight line between these points. For a value x in the interval (𝑥0 ,𝑥1 ) , the
value y along the straight line is given from the equation of slopes

which can be derived geometrically from the figure on the right. It is a special case
of polynomial interpolation with n = 1.
Solving this equation for y, which is the unknown value at x, gives

which is the formula for linear interpolation in the interval (𝑥0 ,𝑦0 ).

In this geometric visualisation, the value at the green circle


multiplied by the horizontal distance between the red and blue
circles is equal to the sum of the value at the red circle multiplied
by the horizontal distance between the green and blue circles, and
the value at the blue circle multiplied by the horizontal distance
between the green and red circles.
Example 1: Fit a straight line y = ax + b for the following data: (Curve Fitting using Least
Square Method)

x 1 3 4 6 8 9 11 14

y 1 2 4 4 5 7 8 9

Solution:
The normal equation for fitting the straight line y = ax + b

 y = a x + nb (1) Where n is the number of data set


 xy = a x2 + b x (2)

x y xy x2

1 1 1 1

3 2 6 9

4 4 16 16

6 4 24 36

8 5 40 64

9 7 63 81

11 8 88 121

14 9 126 196

 x = 56  y = 40  xy = 364  x2 = 524

Substitute the values to equation 1 and 2;


40 = 56a + 8b (eq.1)
364 = 524a + 56b (eq.2)
Use elimination method to determine the value of a
and b
a = 0.64 and b = 0.55
Therefore; y = 0.64x + 0.55 (slope of a line is (+) 0.64 and y intercept is 0.55)
Example 2: (Curve fitting using Least Square Method)

x 0.24 0.26 0.28 0.30

y 1.25 0.80 0.66 0.20

Solution:
Straight Line equation is y = ax + b

 y = a x + nb (1) where n is the number of data set


 xy = a x2 + b x (2)

Substituting these values to the normal equations


2.91 = 1.08a + 4b
0.75 = 0.29a + 1.08b
Solving this two equations using Elimination
Method
a = 22.3125 and b = -5.2969

Therefore; y = 22.3125x - 5.2969 (slope of a line is (+) 22.3125 and y intercept is -5.2969)

Exercise: Use the following data to fit a straight line y = ax + b

x 0 1 2 3 4

y 1 3.85 6.50 9.35 12.05


Example 3: Calculate Fitting a second degree parabola equation y =ax2 + bx + c using the
following data (Curve fitting using Least Square Method)

x 12 10 8 6 4 2

y 6 5 4 3 2 1

Solution:
The equation is y = ax2 + bx + c and the normal equations are

(1) ny = anx2 + bnx + cn

(2) nxy = anx3 + bnx2 + cnx

(3) nx2y = anx4 + bnx3 + cnx2

Substituting these values to the normal equations


21 = 364a + 42b + 6c
182 = 3528a + 364b + 42c
1764 = 36400a + 3528b + 364c
Solving three equations
(1) 364a + 42b + 6c = 21
(2) 3528a + 364b + 42c = 182
(3) 36400a + 3528b + 364c = 1764
Select equation (1) and (2) and eliminate the variable c.
364a + 42b + 6c = 21 = 2548a + 294b + 42c = 147
3528a + 364b + 42c = 182 = 3528a + 364b + 42a = 182
-980a - 70b = -35 (equation 4)
Select the equation (1) and (3), and eliminate variable c.
364a + 42b + 6c = 21 = 66248a + 7644b + 1092c = 3822
36400a + 3528b + 364c = 1764 = 109200a + 10584b + 1092c = 5292
-42952a -2940b = -1470 (equation 5)
Select the equations (4) and (5) and eliminate variable b.
-980a - 70b = -35 = -41160a - 2940b =-1470
-42952a -2940b = -1470 = -42952a - 2940b = -1470
1792a = 0; therefore a = 0
Use back substitution method to determine the values of b and c;
b = 0.5 and c = 0
Substitute the values in the equation y = ax2 + bx + c
Therefore; y = 0x2 + 0.5x + 0

Example 4: Fit cubic equation y = ax3 + bx2 +cx + d using the following data:

x 12 10 8 6 4 2

y 6 5 4 3 2 1

Solution:
The normal equation of y = ax3 + bx2 + cx + d are

(1) ny = anx3 + bnx2 + cnx + dn

(2) nxy = anx4 + bnx3 + cnx2 + dnx

(3) nx2y = anx5 + bnx4 + cnx3 + dnx2


(4) nx3y = anx6 + bnx5 + cnx4 + dnx3

Substituting these values to the normal equations


21 = 3528a + 364b + 42c + 6d (1)
182 = 36400a + 3528b + 364c + 42d (2)
1764 = 390432a + 36400b + 3528c + 364d (3)
18200 = 4298944a + 390432b + 36400c + 3528d (4)
Select equations (1) and (2) and eliminate variable d.
21 = 3528a + 364b + 42c + 6d = 147 = 24696a + 2548b + 294c + 42d
182 = 36400a + 3528b + 364c + 42d = 182 = 36400a + 3528b + 364c + 42d
-35 = -70c -980b -11704a (eq.5)
Select equations (1) and (3) and eliminate variable d.
21 = 3528a + 364b + 42c + 6d = 3822 = 642096a + 66248b + 7644c + 1092d
1764 = 390432a + 36400b + 3528c + 364d = 5292 = 1171296a + 109200b + 10584c + 1092d
-1470 = -529200a - 42952b -2940c (eq.6)
Select equations (1) and (4) and eliminate variable d.
21 = 3528a + 364b + 42c + 6d
18200 = 4298944a + 390432b + 36400c + 3528d

12348 = 2074464a + 214032b + 24696c + 3528d


18200 = 4298944a + 390432b + 36400c + 3528d
-5852 = -2224480a - 176400b -11704c (eq.7)
Select equations (5) and (6) and eliminate variable c.
-35 = -70c -980b -11704a = -1470 = -491568a - 41160b -2940c
-1470 = -529200a - 42952b -2940c = -1470 = -529200a - 42952b -2940c
0 = 37632a + 1792b (eq.8)
Select equations (5) and (7) and eliminate variable c.
-35 = -70c -980b -11704a -29260 = -9784544a - 819280b - 58520c
c-5852 = -2224480a - 176400b -11704c -29260 = -11122400a - 882000b - 58520c
0 = 1337856a + 62720b (eq.9)
Select equations (8) and (9) and eliminate variable b.
0 = 37632a + 1792b 0 = 1317120a +62720b
0 = 1337856a + 62720b 0 = 1337856a +62720b
0 = -20736a; therefore a = 0
Then use back-substitution method to determine the values of b,c and d.
b = 0, c = 0.5 and d = 0
Therefore; y = 0x3 + 0x2 + 0.5x + 0

Linear Interpolation Examples


Example 1: Find the values of y at x = 4 given some set of values (2,4), (6,7)?
Solution:
Example 2: Find the values of f(2) using linear interpolation, given that f(-1) = 4 and f(3) = 6.
Solution:

Example 3: The temperature of a rock at 4PM was 35 degrees Celsius and at 7PM it was 23
degree Celsius. Using linear interpolation, find its temperature at 9PM.
Solution:

Exercise:
1. The first set of values for day three are (3,4), the second set of values for day five are (5,8).
Calculate the estimated height of the plant on the fourth day. Answer: y = 6

Day 1 3 5 7 9

Height
0 4 8 12 16
(mm)
References/ Video Links:
https://www.youtube.com/watch?v=yQsDxOdn1hk&list=PLYdroRCLMg5NTT00m-
7ituVGdtY1X680M&index=1
https://www.youtube.com/watch?v=s7ILfzREF0w&list=PLYdroRCLMg5NTT00m-
7ituVGdtY1X680M&index=3&t=0s

https://www.youtube.com/watch?v=1iJGLcP__s0
http://atozmath.com/CONM/LeastSquare.aspx?q=1&q1=0.24%2c0.26%2c0.28%2c0.30%601.25
%2c0.80%2c0.66%2c0.20%601&do=1#PrevPart
https://www.vedantu.com/formula/linear-interpolation-formula
https://byjus.com/linear-interpolation-formula/
https://study.com/academy/lesson/interpolation-in-statistics-definition-formula-example.html

You might also like