Notes-Curve fitting & Interpolation
Notes-Curve fitting & Interpolation
CURVE FITTING
The curve of best fit is that for which the sum of the squares of the errors
is a minimum. Let the given points be (𝑥1, 𝑦1 ), (𝑥2, 𝑦2 ) … (𝑥𝑛, 𝑦𝑛 ), and let the
corresponding values of 𝑦 on the fitted curve be 𝑦1 ′ , 𝑦2 ′ , . . . . . . . 𝑦𝑛 ′ .
∑ 𝑥𝑦 = 𝑎 ∑ 𝑥 3 + 𝑏 ∑ 𝑥 2 + 𝑐 ∑ 𝑥
2
∑ 𝑥2𝑦 = 𝑎 ∑ 𝑥4 + 𝑏 ∑ 𝑥3 + 𝑐 ∑ 𝑥
Solving these three equations, we get the values of 𝑎, 𝑏, 𝑐. Substituting
these values in the equation 𝑦 = 𝑎𝑥 2 + 𝑏𝑥 + 𝑐, we get the required second
degree curve.
0 1 0 0
1 1.8 1 1.8
2 3.3 4 6.6
3 4.5 9 13.5
4 6.3 16 25.2
10 16.9 30 47.1
∑ 𝑥 = 10, ∑ 𝑦 = 16.9, ∑ 𝑥 2 = 30, ∑ 𝑥𝑦 = 47.1
Substituting in equations (1) and (2),
Solving, we get 𝑎 = 1.33, 𝑏 = 0.72
Hence the required equation is 𝑦 = 1.33𝑥 + 0.72
When 𝑥 = 2.5, 𝑦 = 1.33(2.5) + 0.72 = 4.045
∑ 𝑥𝑦 = 𝑎 ∑ 𝑥 3 + 𝑏 ∑ 𝑥 2 + 𝑐 ∑ 𝑥 — (2)
2
∑ 𝑥 2 𝑦 = 𝑎 ∑ 𝑥 4 + 𝑏 ∑ 𝑥 3 + 𝑐 ∑ 𝑥 − −(3)
∑ 𝑋𝑌 = 𝑎 ∑ 𝑋 3 + 𝑏 ∑ 𝑋 2 + 𝑐 ∑ 𝑋 — (2)
2
∑ 𝑋 2 𝑌 = 𝑎 ∑ 𝑋 4 + 𝑏 ∑ 𝑋 3 + 𝑐 ∑ 𝑋 − −(3)
Total 0 6 28 0 196 40 6
Hence the normal equations are 28a+7c=6
28b=40
196a+28c=6
Therefore a=-0.21429, b=1.4286, c=1.7143
The equation is Y=-0.21429𝑋 2 +1.4286X+1.7143
(i.e) y-357=-0.21429(x − 1932)2 +1.7143+1.4286(x-1932)
(i.e) y=-0.21429𝑥 2 +829.445x-802265.33
Practice problems
1. Fit a straight line to the following data and find the value of y when x
= 3.5
x: 1 2 3 4 5 6
y: 0.5 2.5 2.0 4.0 3.5 6.0
2. Fit a parabola to the following data:
x: 0 1 2 3 4
y 1 1.8 1.3 2.5 6.3
3. Fit a second degree curve to the data:
x: 1 2 3 4 5 6 7 8 9
y: 2 6 7 8 10 11 11 10 9
5. From the table given below, find the best values of 𝑎and𝑏 in the law 𝑦 =
𝑎𝑒 𝑏𝑥 by the method of least squares:
x: 0 5 8 12 20
y: 3.0 1.5 1.0 0.55 0.18
Fit the straight line and parabola of best fit and calculate the sum of the
squares of the residuals in both cases. Which curve is more appropriate
and why?
Interpolation
Given a set of values (𝑥𝑖 , 𝑦𝑖 ), 𝑖 = 0,1,2, . . . . 𝑛, the process of finding the values
of 𝑦 corresponding to non-tabulated values of 𝑥, is called interpolation. In
particular, if 𝑥0 < 𝑥 < 𝑥𝑛 , then the process is called interpolation, and if
𝑥 < 𝑥0or𝑥 > 𝑥𝑛 , then it is called extrapolation. We approximate the
function 𝑦 = 𝑓(𝑥) by polynomials, called interpolating polynomials.
Forward differences
𝛥𝑦0 = 𝑦1 − 𝑦0
𝛥𝑦1 = 𝑦2 − 𝑦1
.......................
𝛥𝑦𝑛−1 = 𝑦𝑛 − 𝑦𝑛−1 are called the first order forward differences of 𝑦.
𝛥is called the forward difference operator.
The differences of the first order differences are called the second order
forward differencesand the differences of the second order differences are
called the third order forward differences
𝛥2 𝑦0 = 𝛥𝑦1 − 𝛥𝑦0 𝛥3 𝑦0 = 𝛥2 𝑦1 − 𝛥2 𝑦0
𝛥2 𝑦1 = 𝛥𝑦2 − 𝛥𝑦1 𝛥3 𝑦1 = 𝛥2 𝑦2 − 𝛥2 𝑦1
....................... .......................
𝛥2 𝑦𝑛−2 = 𝛥𝑦𝑛−1 − 𝛥𝑦𝑛−2 𝛥2 𝑦𝑛−3 = 𝛥𝑦𝑛−2 − 𝛥𝑦𝑛−3
Backward differences
𝛻𝑦1 = 𝑦1 − 𝑦0
𝛻𝑦2 = 𝑦2 − 𝑦1
.......................
𝛻𝑦𝑛 = 𝑦𝑛 − 𝑦𝑛−1 are called the first order backward differences of 𝑦.
𝛻is called the forward difference operator.
When only two pairs of values (𝑥0 , 𝑦0 ), (𝑥1, 𝑦1 ) are given, the formula is
called linear interpolation formula and it reduces to the two- point
equation of a straight line.
When three pairs of values (𝑥0 , 𝑦0 ), (𝑥1 , 𝑦1 ), (𝑥2 , 𝑦2 ) are given, we get
parabolic interpolation formula.
Newton’s backward interpolation formula
Let 𝑥0 , 𝑥1, . . . . . . 𝑥𝑛 be equidistant values of 𝑥, and
𝑦0 , 𝑦1 , . . . . . . 𝑦𝑛 be the corresponding values of 𝑦 = 𝑓(𝑥).
𝑥−𝑥𝑛 𝑣 𝑣(𝑣+1)
Let ℎ = 𝑥𝑖 − 𝑥𝑖−1 , 𝑖 = 1,2, . . . . 𝑛and 𝑣 = . Then𝑦 = 𝑦𝑛 + 1! 𝛻𝑦𝑛 + 𝛻 2 𝑦𝑛 +
ℎ 2!
𝑣(𝑣+1)(𝑣+2)
𝛻 3 𝑦𝑛 +. . . . . . ..
3!
Note: Both Newton’s forward and backward formulas give the same
value at any point and the interpolating polynomials are also the same.
However, the forward difference formula is used for interpolating or
extrapolating near the beginning of the table and the backward difference
formula is used interpolating or extrapolating near the end of the table.
Example 1
1. Find the cubic polynomial which takes the follows the following values:
𝑥 :0 1 2 3
𝑓(𝑥): 1 2 1 10
Hence find 𝑓(4).
Solution: We form the difference table:
𝑥 𝑦 𝛥𝑦 𝛥2 𝑦 𝛥3 𝑦
0 1
1
1 2 -2
-1 12
2 1 10
9
3 10
𝑥 − 𝑥0 𝑥 − 0
𝑢= = =𝑥
ℎ 1
By Newton’s forward interpolation formula,
𝑢 𝑢(𝑢 − 1) 2 𝑢(𝑢 − 1)(𝑢 − 2) 3
𝑦 = 𝑦0 + 𝛥𝑦0 + 𝛥 𝑦0 + 𝛥 𝑦0 +. . . . . . . .
1! 2! 3!
𝑥(𝑥 − 1) 𝑥(𝑥 − 1)(𝑥 − 2)
= 1 + 𝑥(1) + (−2) + (12)
2 6
= 1 + 𝑥 − 𝑥 2 + 𝑥 + 2𝑥 3 − 6𝑥 2 + 4𝑥
= 2𝑥 3 − 7𝑥 2 + 6𝑥 + 1
∴ 𝑓(𝑥) = 2𝑥 3 − 7𝑥 2 + 6𝑥 + 1
∴ 𝑓(4) = 2(43 ) − 7(42 ) + 6(4) + 1
= 41
2.The population of a city taken once in ten years is given below.
Estimate thepopulation in the year 1955.
Solution:
𝑥 𝑦 𝛥𝑦 𝛥2 𝑦 𝛥3 𝑦
1951 35
7
1961 42 9
16 1
1971 58 10
26
1981 84
𝑥−𝑥0 1955−1951
𝑢=𝑢 = = 0.4By Newton’s forward interpolation formula,𝑦
ℎ 10
3.Find the value of y at x=21 and x=28 from the following data:
x : 20 23 26 29
y : 0.3420 0.3907 0.4384 0.4848
Solution:Since x=21 is nearer to the beginning of the table, we use
Newton’s forward formula.We form the difference table. Also
h=constant=3.
𝑥x 𝑦𝑦 𝛥𝑦 𝛥2 𝑦 𝛥3 𝑦
20 0.3420
0.0487
23 0.3907 -0.0010
0.0477 -0.0003
26 0.4384 -0.0013
0.0464
29 0.4848
Below 40 250
120
Below 60 370 -20
100 -10
Below 80 470 -30 20
70 10
Below 100 540 -20
50
Below 120 590
x y 𝛥𝑦 𝛥2 𝑦 𝛥3 𝑦 𝛥4 𝑦
45 114.84
-18.68
50 96.16 5.84
-12.84 -1.84
55 83.32 4 0.68
-8.84 -1.16
60 74.48 2.84
-6
65 68.48
𝑥 − 𝑥0 46 − 45 1
𝑢= = =
ℎ 5 5
y (46) = 114.84-3.7360-0.4672-0.08832-0.0228
y (46) = 110.52568
𝑥 − 𝑥𝑛 63 − 65 −2
𝑣= = =
ℎ 5 5
y (63) = 68.48+2.40-0.3408+0.07424-0.028288
y (63)=70.585152.
x: 2 4 6 8 10
y: 0 0 1 0 0
Solution :
Let us form the difference table.
x y 𝛥𝑦 𝛥2 𝑦 𝛥3 𝑦 𝛥4 𝑦
2 0
0
4 0 1
1 -3
6 1 -2 6
-1 3
8 0 1
0
10 0
𝟏
=𝟔𝟒 (𝒙 − 𝟐)(𝒙 − 𝟒)[𝟖 − 𝟒𝒙 + 𝟐𝟒 + 𝒙𝟐 − 𝟏𝟒𝒙 + 𝟒𝟖]
𝟏
= [𝒙𝟒 − 𝟐𝟒𝒙𝟑 + 𝟏𝟗𝟔𝒙𝟐 − 𝟔𝟐𝟒𝒙 + 𝟔𝟒𝟎]
𝟔𝟒
Divided differences⏃
Problems
1 1
1.if 𝑓(𝑥) = 𝑥 . 𝑓𝑖𝑛𝑑 𝑡ℎ𝑒 𝑑𝑖𝑣𝑖𝑑𝑒𝑑 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝑜𝑓 𝑓(𝑎, 𝑏, 𝑐, 𝑑)𝑜𝑟 𝑠ℎ𝑜𝑤 𝑡ℎ𝑎𝑡 ∆3𝑏𝑐𝑑 (𝑎) =
1
− (𝑎𝑏𝑐𝑑 )
1 1 1
Solution : Given 𝑓(𝑥) = 𝑥 𝑡ℎ𝑒𝑛 𝑓(𝑎) = 𝑎 , 𝑓(𝑏) = 𝑏
1 1 𝑎−𝑏
𝑓(𝑏) − 𝑓(𝑎) 𝑏 − 𝑎
𝑓(𝑎, 𝑏) = = = 𝑎𝑏
𝑏−𝑎 𝑏−𝑎 𝑏−𝑎
−1
𝑓(𝑎, 𝑏) =
𝑎𝑏
𝑓(𝑏, 𝑐) − 𝑓(𝑎, 𝑏)
𝑓(𝑎, 𝑏, 𝑐) =
𝑐−𝑎
−1 (−1) −𝑎𝑏+𝑏𝑐
− 𝑏(𝑎𝑐𝑏)
𝑏𝑐 𝑎𝑏
𝑓(𝑎, 𝑏, 𝑐) = =
𝑐−𝑎 𝑐−𝑎
𝑏(−𝑎+𝑐)
𝑏(𝑎𝑐𝑏) 1
𝑓(𝑎, 𝑏, 𝑐) = =
𝑐−𝑎 𝑎𝑏𝑐
Similarly
𝑓(𝑏, 𝑐, 𝑑) − 𝑓(𝑎, 𝑏, 𝑐) −1
𝑓(𝑎, 𝑏, 𝑐, 𝑑) = =
𝑑−𝑎 𝑎𝑏𝑐𝑑
𝑥: 3 7 9 10
𝑓(𝑥): 168 120 72 63
Solution:
𝑥 𝑓(𝑥) ⏃𝑓(𝑥) ⏃2𝑓(𝑥) ⏃3𝑓(𝑥)
3 168
120 − 168
7−3
= −12
7 120 −24 − (−12)
9−3
= −2
72 − 120 1
9−7
= −24
9 72 5
63 − 72
= −9
10 − 9
10 63
= 93
3.Use Newton’s formula to find 𝑓(𝑥)from the following data and hence find
𝑓(6):
𝑥: 1 2 7 8
𝑦: 1 5 5 4
Note:
When 𝑛 = 2,
(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) (𝑥 − 𝑥0)(𝑥 − 𝑥2 ) (𝑥 − 𝑥0 )(𝑥 − 𝑥1)
𝑦 = 𝑓(𝑥) = 𝑦0 + 𝑦1 + 𝑦
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 ) (𝑥1 − 𝑥0)(𝑥1 − 𝑥2 ) (𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 ) 2
When 𝑛 = 3,
(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )(𝑥 − 𝑥3) (𝑥 − 𝑥0 )(𝑥 − 𝑥2 )(𝑥 − 𝑥3 )
𝑦 = 𝑓(𝑥) = 𝑦0 + 𝑦 +
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 )(𝑥0 − 𝑥3 ) (𝑥1 − 𝑥0 )(𝑥1 − 𝑥2 )(𝑥1 − 𝑥3 ) 1
(𝑥 − 𝑥0 )(𝑥 − 𝑥1)(𝑥 − 𝑥3 ) (𝑥 − 𝑥0)(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )
𝑦2 + 𝑦
(𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )(𝑥2 − 𝑥3 ) (𝑥3 − 𝑥0)(𝑥3 − 𝑥1 )(𝑥3 − 𝑥2) 3
Putting x=10,
(4)(1)(−1) (5)(1)(−1)
𝑦 = 𝑓(10) = (12) + (13) +
(−1)(−4)(−6) (1)(−3)(−5)
(5)(4)(−1) (5)(4)(1)
(14) + (16)
(4)(3)(−2) (6)(5)(2)
=14.6666.
. Solution:
From the equation ,the values of x are
By Lagrange’s formula,
(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )(𝑥 − 𝑥3) (𝑥 − 𝑥0 )(𝑥 − 𝑥2 )(𝑥 − 𝑥3 )
𝑦 = 𝑓(𝑥) = 𝑦0 + 𝑦 +
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 )(𝑥0 − 𝑥3 ) (𝑥1 − 𝑥0 )(𝑥1 − 𝑥2 )(𝑥1 − 𝑥3 ) 1
(𝑥 − 𝑥0 )(𝑥 − 𝑥1)(𝑥 − 𝑥3 ) (𝑥 − 𝑥0)(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )
𝑦2 + 𝑦
(𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )(𝑥2 − 𝑥3 ) (𝑥3 − 𝑥0)(𝑥3 − 𝑥1 )(𝑥3 − 𝑥2) 3
=0.19-0.31+0.938 +2.8125
=3.63
Lagrange’s inverse interpolation formula
Let 𝑥0 , 𝑥1, 𝑥2 , . . . . . . . . . . , 𝑥𝑛 be the values of the function 𝑥 = 𝑓(𝑦)corresponding
to the arguments 𝑦0 , 𝑦1 , 𝑦2 , . . . . . . . . . . , 𝑦𝑛 , which are not necessarily equally
spaced (i.e., may or may not be equally spaced). Then
(𝑦 − 𝑦1 )(𝑦 − 𝑦2 ). . . . . . (𝑦 − 𝑦𝑛 ) (𝑦 − 𝑦0 )(𝑦 − 𝑦2 ). . . . . . (𝑦 − 𝑦𝑛 )
𝑥 = 𝑓(𝑦) = 𝑥0 + 𝑥
(𝑦0 − 𝑦1 )(𝑦0 − 𝑦2 ). . . . . . (𝑦0 − 𝑦𝑛 ) (𝑦1 − 𝑦0 )(𝑦1 − 𝑦2 ). . . . . . (𝑦1 − 𝑦𝑛 ) 1
(𝑦 − 𝑦0 )(𝑦 − 𝑦1 ). . . . . . (𝑦 − 𝑦𝑛−1 )
+. . . . . . . . . . . 𝑥
(𝑦𝑛 − 𝑦0 )(𝑦𝑛 − 𝑦1 ). . . . . . (𝑦𝑛 − 𝑦𝑛−1 ) 𝑛
Problems:
1.Using Lagrange’s inverse interpolation formula, find the value of x
from the following data when y=13.5
𝑥: 93 96.2 100 104.2 108.7
𝑦: 11..38 12.80 14.70 17.07 19.91
Solution
ByLagrange’s inverse interpolation formula
X0=93,x1=96.2, x2=100, x3=104.2, x4=108.7
= 𝑓(𝑦)
(𝑦 − 12.80)(𝑦 − 14.70)(𝑦 − 17.07)(𝑦 − 19.91)
= (93)
(11.38 − 12.80))(11.38 − 14.70)(11.38 − 17.07)(11.38 − 19.91)
(𝑦 − 11.38)(𝑦 − 14.70)(𝑦 − 17.07)(𝑦 − 19.91)
+ (96.2)
(12.80 − 11.38))(12.80 − 14.70)(12.80 − 17.07)(12.80 − 19.91)
(𝑦 − 11.38)(𝑦 − 12.80)(𝑦 − 17.07)(𝑦 − 19.91)
+ (100)
(14.70 − 11.38))(14.70 − 12.80)(14.70 − 17.07)(14.70 − 19.91)
(𝑦 − 11.38)(𝑦 − 12.80)(𝑦 − 14.70)(𝑦 − 19.91)
+ (104.2) +
(17.07 − 11.38))(17.07 − 12.80)(17.07 − 14.70)(17.07 − 19.91)
(𝑦 − 11.38)(𝑦 − 12.80)(𝑦 − 14.70)(𝑦 − 17.07)
(108.7)
(19.91 − 11.38))(19.91 − 12.80)(19.91 − 14.70)(19.91 − 19.91)
Solution
(13.6 − 14.9)(13.6 − 14.1)(13.6 − 13.3)(13.6 − 12.5)
𝑥= (30) +
(15.9 − 14.9)(15.9 − 14.1)(15.9 − 13.3)(15.9 − 12.5)
(13.6 − 15.9)(13.6 − 14.1)(13.6 − 13.3)(13.6 − 12.5)
(35) +
(14.9 − 15.9)(14.9 − 14.1)(14.9 − 13.3)(14.9 − 12.5)
(13.6 − 15.9)(13.6 − 14.9)(13.6 − 13.3)(13.6 − 12.5)
(40) +
(14.1 − 15.9)(14.1 − 14.9)(14.1 − 13.3)(14.1 − 12.5)
(13.6 − 15.9)(13.6 − 14.9)(13.6 − 14.1)(13.6 − 12.5)
(45) +
(13.3 − 15.9)(13.3 − 14.9)(13.3 − 14.1)(13.3 − 12.5)
(13.6 − 15.9)(13.6 − 14.9)(13.6 − 14.1)(13.6 − 13.3)
(50)
(12.5 − 15.9)(12.5 − 14.9)(12.5 − 14.1)(12.5 − 13.3)
X(13.6)=43