[go: up one dir, main page]

0% found this document useful (0 votes)
15 views59 pages

Chapter 3-3

Curve fitting is the process of determining the best-fit curve for a dataset, typically represented by an algebraic equation relating two variables. The document outlines methods for fitting straight lines and parabolas to data, including forming normal equations and solving for coefficients. Several examples illustrate the application of these methods to find the equations of best-fit lines and parabolas based on provided data points.

Uploaded by

gooorr66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views59 pages

Chapter 3-3

Curve fitting is the process of determining the best-fit curve for a dataset, typically represented by an algebraic equation relating two variables. The document outlines methods for fitting straight lines and parabolas to data, including forming normal equations and solving for coefficients. Several examples illustrate the application of these methods to find the equations of best-fit lines and parabolas based on provided data points.

Uploaded by

gooorr66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Unit-3

Curve Fitting

115

21
1
Curve fitting
 Curve fitting is the process of finding the ‘best-fit’ curve for a given
set of data. It is the representation of the relationship between
two variables by means of an algebraic equation.

2
Fitting the straight line
𝑦 = 𝑎𝑥 + 𝑏

3
Working procedure:
To fit the straight line 𝑦 = 𝑎𝑥 + 𝑏

𝑥𝑦 = 𝑎𝑥 + 𝑏𝑥 𝑦= 𝑎𝑥 + 𝑏

𝑥𝑦 = 𝑎 𝑥 +𝑏 𝑥 𝑦=𝑎 𝑥 + 𝑛𝑏

4
Working procedure:
To fit the straight line 𝑦 = 𝑎𝑥 + 𝑏
 Form the normal equations

𝑦=𝑎 𝑥 + 𝑛𝑏

𝑥𝑦 = 𝑎 𝑥 +𝑏 𝑥

 Solve these normal equations as simultaneous equation for 𝑎 & 𝑏.


 Substitute the values of 𝑎 & 𝑏 in 𝑦 = 𝑎𝑥 + 𝑏.Which is the required
line of best fit.

5
Working procedure:
To fit the straight line 𝑦 = 𝑎 + 𝑏𝑥

𝑦= 𝑎+ 𝑏𝑥 𝑥𝑦 = 𝑎𝑥 + 𝑏𝑥

𝑦 = 𝑎𝑛 + 𝑏 𝑥 𝑥𝑦 = 𝑎 𝑥+𝑏 𝑥

6
Working procedure:
To fit the straight line 𝑦 = 𝑎 + 𝑏𝑥
 Form the normal equations

𝑦 = 𝑛𝑎 + 𝑏 𝑥

𝑥𝑦 = 𝑎 𝑥+𝑏 𝑥

 Solve these normal equations as simultaneous equation for 𝑎 & 𝑏.


 Substitute the values of 𝑎 & 𝑏 in 𝑦 = 𝑎 + 𝑏𝑥.Which is the required
line of best fit.

7
Example 1
Find the equation 𝑦 = 𝑎𝑥 + 𝑏 of the best fitting straight
line for the following data
𝑥 −1 0 1 2
𝑦 1 0 1 4
Solution:
Let the straight line to be fitted to the data be 𝒚 = 𝒂𝒙 + 𝒃
The normal equations are
𝑦=𝑎 𝑥 + 𝑛𝑏 (1)

𝑥𝑦 = 𝑎 𝑥 +𝑏 𝑥 (2)

8
Example 1
𝒙 𝒚 𝒙𝟐 𝒙𝒚
-1 1 1 -1
0 0 0 0
1 1 1 1
2 4 4 8

𝑥=2 𝑦=6 𝑥 =6 𝑥𝑦 = 8

9
Example
Example 1

Here, Total no. of data points 𝑛 = 4


Substituting these values in equation 1 and 2
𝑦=𝑎 𝑥 + 𝑛𝑏 ⇒ 6 = 2 𝑎 + 4 𝑏 … … … (3)

𝑥𝑦 = 𝑎 𝑥 +𝑏 𝑥 ⇒8=6𝑎+2𝑏 … … … (4)

Solving equation (3) and (4)


𝑖. 𝑒. , 𝐸𝑞 3 − 2 X 𝐸𝑞 (4)
2𝑎 + 4𝑏 = 6
12𝑎 + 4𝑏 = 16
− − −
−10𝑎 = −10
⇒𝑎=1

10
Example
Using Eq (3)

We get,
6 = 2𝑎 + 4𝑏

⇒ 6 = 2 1 + 4𝑏 (∵ 𝑎 = 1)

⇒ 4𝑏 = 4

⇒𝑏=1

So, 𝑎 = 1 and 𝑏 = 1

Hence, the required Eq of straight line is,


𝑦 = 𝑎𝑥 + 𝑏 ⇒ 𝑦 = 𝑥 + 1

11
Example
Find the equation 𝑦 = 𝑎𝑥 + 𝑏 of the best fitting straight
line for the following data
X -5 -3 -1 0 1 2 4
Y 0.4 -0.1 -0.2 -0.3 -0.3 0.1 0.4

Solution:
Let the straight line to be fitted to the data be 𝒚 = 𝒂𝒙 + 𝒃
The normal equations are
𝑦=𝑎 𝑥 + 𝑛𝑏 (1)

𝑥𝑦 = 𝑎 𝑥 +𝑏 𝑥 (2)

12
Example

𝒙 𝒚 𝒙𝟐 𝒙𝒚
−5 0.4 25 −2
−3 −0.1 9 0.3
−1 −0.2 1 0.2
0 −0.3 0 0
1 −0.3 1 −0.3
0.1 4 0.2
2
4 0.4 16 1.6

𝑥 = −2 𝑦=0 𝑥 = 56 𝑥𝑦 = 0

13
Example
Total no. of data points 𝑛 = 7
Substituting these values in equation 1 and (2)
𝑦=𝑎 𝑥 + 𝑛𝑏 ⇒ 0 = −2 𝑎 + 7 𝑏 … … … (3)

𝑥𝑦 = 𝑎 𝑥 +𝑏 𝑥 ⇒ 0 = 56 𝑎 − 2 𝑏 … … … (4)

Solving equation (3) and (4)

𝑖. 𝑒. , 2 X 𝐸𝑞 3 + 7 X 𝐸𝑞 (4)

−4𝑎 + 14𝑏 = 0
392𝑎 − 14𝑏 = 0
388𝑎 = 0
⇒𝑎=0

14
Example
Using Eq (3)

We get,
−2𝑎 + 7𝑏 = 0
⇒ −2 0 + 7𝑏 = 0 (∵ 𝑎 = 0)
⇒ 7𝑏 = 0
⇒𝑏=0

So, 𝑎 = 0 and 𝑏 = 0

Hence, the required Eq of straight line is,


𝑦 = 𝑎𝑥 + 𝑏 ⇒ 𝑦 = 0 𝑥 + 0 = 0
15
Example
Find the equation 𝑦 = 𝑎𝑥 + 𝑏 of the best fitting straight line for the
following data
x -1 0 1 2
Y 1 1 1 -5

Solution:
Let the straight line to be fitted to the data be 𝒚 = 𝒂𝒙 + 𝒃
The normal equations are
𝑦=𝑎 𝑥 + 𝑛𝑏 (1)

𝑥𝑦 = 𝑎 𝑥 +𝑏 𝑥 (2)

16
Example

𝒙 𝒚 𝒙𝟐 𝒙𝒚
−1 1 1 −1
0 1 0 0
1 1 1 1
2 −5 4 −10

𝑥=2 𝑦 = −2 𝑥 =6 𝑥𝑦 = −10

17
Example
Here, Total no. of data points 𝑛=4
Substituting these values in equation 1 and (2)
𝑦=𝑎 𝑥 + 𝑛𝑏 ⇒ −2 = 2𝑎 + 4𝑏 (3)

𝑥𝑦 = 𝑎 𝑥 +𝑏 𝑥 ⇒ −10 = 6𝑎 + 2𝑏 (4)

Solving equation (3) and (4)


𝑖. 𝑒. , 𝐸𝑞 3 + 2 X 𝐸𝑞 (4)

2𝑎 + 4𝑏 = −2
12𝑎 + 4𝑏 = −20
− − −
−10𝑎 = 18
⇒ 𝑎 = −1.8
18
Example
Using Eq (3)
We get,

2𝑎 + 4𝑏 = −2
⇒ 2 −1.8 + 4𝑏 = −2 (∵ 𝑎 = −1.8)
⇒ 4𝑏 = −2 −1.8 − 2
⇒ 𝑏 = 0.4

So, 𝑎 = −1.8 and 𝑏 = 0.4


Hence, the required Eq of straight line is,

𝑦 = 𝑎𝑥 + 𝑏 ⇒ 𝑦 = −1.8𝑥 + 0.4

19
Fitting the Parabola
𝑦 = 𝑎𝑥 + 𝑏𝑥 + 𝑐

20
Working procedure:
To fit the parabola 𝑦 = 𝑎𝑥 + 𝑏𝑥 + c

 Form the normal equations


𝑦=𝑎 𝑥 +𝑏 𝑥 + 𝑛𝑐

𝑥𝑦=𝑎 𝑥 +𝑏 𝑥 +𝑐 𝑥

𝑥 𝑦=𝑎 𝑥 +𝑏 𝑥 +𝑐 𝑥

 Solve these equations for 𝑎, 𝑏, & 𝑐.


 Substitute the values of 𝑎, 𝑏, 𝑐 in𝑦 = 𝑎𝑥 + 𝑏𝑥 + 𝑐
21
Working procedure:
To fit the parabola 𝑦 = 𝑎 + 𝑏𝑥 + c𝑥

 Form the normal equations


𝑦 = 𝑛𝑎 + 𝑏 𝑥+𝑐 𝑥

𝑥𝑦 = 𝑎 𝑥+𝑏 𝑥 +𝑐 𝑥

𝑥 𝑦=𝑎 𝑥 +𝑏 𝑥 +𝑐 𝑥

 Solve these equations for 𝑎, 𝑏, & 𝑐.


 Substitute the values of 𝑎, 𝑏, 𝑐 in𝑦 = 𝑎 + 𝑏𝑥 + 𝑐𝑥
22
Example
Fit a parabola of second degree 𝒚 = 𝒂 + 𝒃𝒙 + 𝒄𝒙𝟐 .
𝒙 −𝟏 𝟎 𝟏 𝟐
𝑦 −2 1 2 4

Solution:
Let the equation of the parabola be 𝑦 = 𝑎 + 𝑏𝑥 + 𝑐𝑥 .
The normal equations are

𝒚 = 𝒏𝒂 + 𝒃 𝒙+𝒄 𝒙𝟐 … . (𝟏)

𝒙𝒚 = 𝒂 𝒙+𝒃 𝒙𝟐 + 𝒄 𝒙𝟑 … (𝟐)

𝒙𝟐 𝒚 = 𝒂 𝒙𝟐 + 𝒃 𝒙𝟑 + 𝒄 𝒙𝟒 … . (𝟑)

23
𝑥 𝑦 𝑥 𝑥 𝑥 𝑥𝑦 𝑥 𝑦
−1 −2 1 −1 1 2 −2
0 1 0 0 0 0 0
1 2 1 1 1 2 2
2 4 4 8 16 8 16

𝑥 𝑦 𝑥 𝑥 𝑥 𝑥𝑦 𝑥 𝑦

=2 =5 =6 =8 = 18 = 12 = 16
Here 𝑛 = 4
Substituting these values in equations (1), (2), & (3). We get,
𝒚 = 𝒏𝒂 + 𝒃 𝒙+𝒄 𝒙𝟐 ⇒ 5 = 4 𝑎 + 2 𝑏 + 6 𝑐 −−− −(4)

𝒙𝒚 = 𝒂 𝒙+𝒃 𝒙𝟐 + 𝒄 𝒙𝟑 ⇒ 12 = 2 𝑎 + 6 𝑏 + 8 𝑐 −−− −(5)

𝒙𝟐 𝒚 = 𝒂 𝒙𝟐 + 𝒃 𝒙𝟑 + 𝒄 𝒙𝟒 ⇒ 16 = 6 𝑎 + 8 𝑏 + 18 𝑐 −−− −(6)

24
So, we get node
5=4𝑎+2𝑏+6𝑐
Tnt
… … (4)
12 = 2 𝑎 + 6 𝑏 + 8 𝑐 … … (5)
16 = 6 𝑎 + 8 𝑏 + 18 𝑐 … … (6)

Solving equation (4) & (5) Solving equation (5) & (6)
i.e., 𝐸𝑞 . 4 + 2 ∗ 𝐸𝑞 (5) i.e., 3 ∗ 𝐸𝑞 . 5 + 𝐸𝑞 (6)
5 = 4𝑎 + 2𝑏 + 6𝑐 36 = 6𝑎 + 18𝑏 + 24𝑐
24 = 4𝑎 + 12𝑏 + 16𝑐 16 = 6𝑎 + 8𝑏 + 18𝑐

19 = 10𝑏 + 10𝑐 … … (7) 20 = 10𝑏 + 6𝑐 … … 8

Solving equation (7) & (8)


19 = 10𝑏 + 10𝑐
20 = 10𝑏 + 6𝑐
1
−1 = 4𝑐 ⇒ 𝑐 = − ⇒ 𝑐 = −0.25
4
25
Using eq. (8)
20 = 10𝑏 + 6𝑐
⇒ 20 = 10𝑏 + 6 −0.25
⇒ 20 = 10𝑏 − 1.5
⇒ 𝑏 = 2.15
Using eq. (4)
5 = 4𝑎 + 2𝑏 + 6𝑐
⇒ 5 = 4𝑎 + 2 2.15 + 6 −0.25
⇒ 𝑎 = 0.55
Hence, the required Eq of Parabola is,
𝑦 = 𝑎 + 𝑏𝑥 + 𝑐𝑥 ⇒ 𝑦 = 0.55 + 2.15𝑥 − 0.25𝑥
26
Example
Fit a parabola of second degree 𝒚 = 𝒂 + 𝒃𝒙 + 𝒄𝒙𝟐 .
𝒙 −𝟏 𝟎 𝟏 𝟐
𝑦 2 1 0 −2

Solution:
Let the equation of the parabola be 𝑦 = 𝑎 + 𝑏𝑥 + 𝑐𝑥 .
The normal equations are

𝒚 = 𝒏𝒂 + 𝒃 𝒙+𝒄 𝒙𝟐 … . (𝟏)

𝒙𝒚 = 𝒂 𝒙+𝒃 𝒙𝟐 + 𝒄 𝒙𝟑 … (𝟐)

𝒙𝟐 𝒚 = 𝒂 𝒙𝟐 + 𝒃 𝒙𝟑 + 𝒄 𝒙𝟒 … . (𝟑)

27
𝑥 𝑦 𝑥 𝑥 𝑥 𝑥𝑦 𝑥 𝑦
−1 2 1 −1 1 −2 2
0 1 0 0 0 0 0
1 0 1 1 1 0 0
2 −2 4 8 16 −4 −8

𝑥 𝑦 𝑥 𝑥 𝑥 𝑥𝑦 𝑥 𝑦

=2 =1 =6 =8 = 18 = −6 = −6

Here 𝑛 = 4. Substituting these values in equations 1, 2, & 3.We get,


1 = 4𝑎 + 2𝑏 + 6𝑐 −−− −(4)
−6 = 2𝑎 + 6𝑏 + 8𝑐 −−− −(5)
−6 = 6𝑎 + 8𝑏 + 18𝑐 −−− −(6)

By 4, & 5 By 5, & 6
1 = 4𝑎 + 2𝑏 + 6𝑐 −18 = 6𝑎 + 18𝑏 + 24𝑐
−12 = 4𝑎 + 12𝑏 + 16𝑐 −6 = 6𝑎 + 8𝑏 + 18𝑐
13 = −10𝑏 − 10𝑐 −−− −(7) −12 = 10𝑏 + 6𝑐 −−− −(8)

28
By using eq. 7, &8
13 = −10𝑏 − 10𝑐
−12 = 10𝑏 + 6𝑐
1 = − 4𝑐

⇒𝑐=−
1
4 well
91
⇒ 𝑐 = −0.25

Using eq. 7 Using eq. 4


13 = −10𝑏 − 10𝑐 1 = 4𝑎 + 2 −1.05 + 6 −0.25
⇒ 13 = −10𝑏 − 10 −0.25 ⇒ 𝑎 = 1.15
⇒ 10𝑏 = −13 + 2.5
⇒ 𝑏 = −1.05

𝑦 = 𝑎 + 𝑏𝑥 + 𝑐𝑥 ⇒ 𝑦 = 1.15 − 1.05𝑥 − 0.25𝑥


29
iwv

Non-Polynomial Approximation
“OR”
Non-Linear Regression

30
Fitting a curve 𝑦 = 𝑎𝑒

 𝑦 = 𝑎𝑒 Yields

Taking Logarithm on both sides ln 𝑦 = l𝑛 𝑎


+ l𝑛 𝑒

∴ l𝑛 𝑦 = l𝑛 𝑎 + 𝑏𝑥 (∵ 𝑙𝑛 𝑒 = 𝑥)

31
Fitting a curve 𝑦 = 𝑎𝑥

 𝑦 = 𝑎𝑥 Yields

Taking Logarithm on both sides

l𝑛 𝑦 = ln 𝑎 + ln 𝑥b
l𝑛 𝑦 = ln 𝑎 + b ln 𝑥

32
Fitting a curve 𝑦 = 𝑎𝑏

𝑦 = 𝑎𝑏 Yields

Taking Logarithm on both sides


ln 𝑦 = ln 𝑎 + ln 𝑏𝑥

ln 𝑦 = ln 𝑎 + 𝑥 ln 𝑏

33
Example
Fit a curve of the form 𝑦 = 𝑎𝑥 to the following data

x 20 16 10 11 14
Y 22 41 120 89 56

Solution:

The curve of best fit is 𝑦 = 𝑎𝑥 .


Taking logarithm on both the sides,

𝑙𝑛 𝑦 = 𝑙𝑛 𝑎 + 𝑙𝑛 𝑥

⇒ 𝑙𝑛𝑦 = 𝑙𝑛 𝑎 + 𝑏 𝑙𝑛 𝑥

34
Example
⇒ 𝑙𝑛𝑦 = 𝑙𝑛 𝑎 + 𝑏 𝑙𝑛 𝑥
Now, We take
𝑙𝑛 𝑎 = 𝐴

We get , 𝑙𝑛𝑦 = 𝐴 + 𝑏 𝑙𝑛 𝑥
The normal equations are

ln 𝑦 = 𝑛𝐴 + 𝑏 ln 𝑥 … … … (1)

ln 𝑥 ∗ ln 𝑦 = 𝐴 ln 𝑥 + 𝑏 (ln 𝑥) … … … (2)

35
Example
𝑥 𝑦 𝑙𝑛 𝑥 𝑙𝑛 𝑦 (𝑙𝑛𝑥) (ln 𝑥 ∗ ln 𝑦)
20 22 2.9957 3.0910 8.9742 9.2597
16 41 2.7726 3.7136 7.6873 10.2963
10 120 2.3026 4.7875 5.3020 11.0237
11 89 2.3979 4.4886 5.7499 10.7632
14 56 2.6391 4.0254 6.9648 10.6234

𝑙𝑛𝑥 = 13.1079 𝑙𝑛𝑦 = 20.1061 (𝑙𝑛𝑥) = 34.6782 ln 𝑥 ∗ ln 𝑦 = 51.9663

Here, No. of data n=5 Substituting these values in equation 1 and (2)
ln 𝑦 = 𝑛𝐴 + 𝑏 ln 𝑥 ⇒ 20.1061 = 5 𝐴 + 13.1079 𝑏 ……… 3

ln 𝑥 ∗ ln 𝑦 = 𝐴 ln 𝑥 + 𝑏 (ln 𝑥) ⇒ 51.9663 = 13.1079 𝐴 + 34.6782 𝑏 … … … (4)

36
Example
20.1061 = 5𝐴 + 13.1079𝑏 ……… 3
51.9663 = 13.1079𝐴 + 34.6782𝑏 … … … (4)
Solving 𝐸𝑞 3 𝑎𝑛𝑑 (4)
𝑖. 𝑒. , 13.1079 X 𝐸𝑞 3 − 5 X 𝐸𝑞 (4)
263.5487 = 65.5395𝐴 + 171.8170𝑏
259.8315 = 65.5395𝐴 + 173.3910𝑏
− − −
3.7172 = −1.5740𝑏
⇒ 𝑏 = −2.3616

37
Example
Using Eq 3 We get,

20.1061 = 5𝐴 + 13.1079𝑏
⇒ 5𝐴 = 20.1061 − 13.1079 −2.3616
⇒ 𝐴 = 10.2123
We know that,
𝑙𝑛 𝑎 = 𝐴

⇒ 𝑎 = 𝑒𝐴
Therefore, a = 27236.1387
Hence, the required Eq of curve is,
𝑦 = 𝑎𝑥 ⇒ 𝑦 = 27236.1387𝑥 .

38
Example
Fit a curve of the form 𝑦 = 𝑎𝑏 to the following data. Hence find 𝑓 8 .

x 1 2 3 4 5 6 7
y 87 97 113 129 202 195 193

Solution:

The curve of best fit is 𝑦 = 𝑎𝑏 .


Taking logarithm on both the sides,

𝑙𝑛 𝑦 = 𝑙𝑛 𝑎 + 𝑙𝑛 𝑏

⇒ 𝑙𝑛𝑦 = 𝑙𝑛 𝑎 + 𝑥 𝑙𝑛 𝑏

39
Example
⇒ 𝑙𝑛𝑦 = 𝑙𝑛 𝑎 + 𝑥 𝑙𝑛 𝑏
Now, We take
𝑙𝑛 𝑎 = 𝐴
𝑙𝑛 𝑏 = 𝐵
We get , 𝑙𝑛𝑦 = 𝐴 + 𝑥𝐵
The normal equations are
𝑙𝑛𝑦 = 𝑛𝐴 + 𝐵 𝑥 … … … (1)

𝑥𝑙𝑛𝑦 = 𝐴 𝑥+𝐵 𝑥 … … … (2)

40
Example
𝑥 𝑦 𝑙𝑛 𝑦 𝑥 lny
1 87 4.4659 4.4659
2 97 4.5747 9.1494
3 113 4.7274 14.1822
4 129 4.8598 19.4392
5 202 5.3083 26.5415
6 195 5.2730 31.6380
7 193 5.2627 36.8389
∑𝑥 𝑙𝑛𝑦 = 34.4718 𝑥𝑙𝑛𝑦 = 142.2551
=28

𝑥 = 140

41
Example
Here, No. of data n=7 Substituting these values in equation 1 and (2)
𝑙𝑛𝑦 = 𝑛𝐴 + 𝐵 𝑥 ⇒ 34.4718 = 7 𝐴 + 28 𝐵 ……… 3

𝑥𝑙𝑛𝑦 = 𝐴 𝑥+𝐵 𝑥 ⇒ 142.2551 = 28 𝐴 + 140 B … … … (4)

42
34.4718 = 7𝐴 + 28𝐵 ……… 3
142.2551 = 28𝐴 + 140B ……… 4

Solving Equation (3) and (4)


We get,
𝐴 = 4.3006, & 𝐵 = 0.1560
We know that,
𝑙𝑛 𝑎 = 𝐴 & 𝑙𝑛 𝑏 = 𝐵

⇒ 𝑎 = 𝑒𝐴 & 𝑏 = 𝑒𝐵
Therefore, a = 73.7440 & 𝑏 = 1.1688
Hence, the required Eq of curve is,
𝑦 = 𝑎𝑏 ⇒ 𝑦 = 73.7440(1.1688 )

⇒ 𝑦 8 = 256.8315
43
Curve Fitting with Cubic
Spline

44
Step to obtain Cubic spline
1. Find the values of 𝑀 , 𝑀 , 𝑀 , 𝑀 for 𝑖 = 1,2, … 𝑛
By using formula
6
𝑀 + 4𝑀 + 𝑀 = 𝑦 − 2𝑦 + 𝑦 𝑓𝑜𝑟 𝑖 = 1 𝑡𝑜 𝑛 − 1

Choose 𝑀 = 𝑀 = 0 (Natural spline)
2. Write cubic spline as
𝑥−𝑥 𝑥−𝑥
𝑓 𝑥 = 𝑀 + 𝑀
6ℎ 6ℎ
𝑥 −𝑥 ℎ 𝑥−𝑥 ℎ
+ 𝑦 − 𝑀 + 𝑦 − 𝑀
ℎ 6 ℎ 6

45
Example
Consider the values given in the following table:
x 0 1 2 3
𝑌 = 𝑓(𝑥) 1 2 33 244

With 𝑀 = 0, 𝑀 = 0. Hence, find the cubic spline and y 2.5 .


Solution :
Here, step-size ℎ = 1
No. of intervals 𝑛 = 3
𝑀 =0&𝑀 =0

46
Example

For cubic spline interpolation,


6
𝑀 + 4𝑀 + 𝑀 = 𝑦 − 2𝑦 + 𝑦 , 𝑖 = 1 𝑡𝑜 𝑛 − 1

Now, For 𝑖 = 1
𝑀 + 4𝑀 + 𝑀 = (𝑦 − 2𝑦 + 𝑦 ) ∵ ℎ = 1, 𝑦 = 2, 𝑦 = 33
= 6(1 − 2(2) + 33)
= 180
4𝑀 + 𝑀 = 180 ∵𝑀 =0 … … … (1)

47
Example

For 𝑖 = 2
6
𝑀 + 4𝑀 + 𝑀 = (𝑦 − 2𝑦 + 𝑦 )
1
6
∵ ℎ = 1, 𝑀 + 4𝑀 + 𝑀 = 𝑦 − 2𝑦 + 𝑦

= 6[2 − 2(33) + 244]
∵ 𝑦 = 33, 𝑦 = 244
= 1080
𝑀 + 4𝑀 = 1080 ∵𝑀 =0 … … … (2)

48
Example

Now, we have
4𝑀 + 𝑀 = 180 ……… 1
𝑀 + 4𝑀 = 1080 … … … (2)
Solving Eq 1 and (2),
𝑖. 𝑒. , 4 ∗ Eq 1 − Eq 2

16𝑀 + 4𝑀 = 720 Using Eq 1 ,


𝑀 + 4𝑀 = 1080 4𝑀 + 𝑀 = 180
− − − ⇒ 𝑀 = 180 − 4 −24 (∵ 𝑀 = −24)
15𝑀 = −360 ⇒ 𝑀 = 276
⇒ 𝑀 = −24

49
Example

The cubic spline functions are given by


1
𝑓 𝑥 = 𝑥 −𝑥 𝑀 + 𝑥−𝑥 𝑀
6ℎ

𝑥 −𝑥 ℎ 𝑥−𝑥 ℎ
+ 𝑦 − 𝑀 + 𝑦 − 𝑀
ℎ 6 ℎ 6

Where, 𝑖 = 0,1,2, … 𝑛

50
For 𝑖 = 0 in the interval 0 ≤ 𝑥 ≤ 1,
1
𝑓 𝑥 = 𝑥 −𝑥 𝑀 + 𝑥−𝑥 𝑀
6(1)

𝑥 −𝑥 (1) 𝑥−𝑥 (1)


+ 𝑦 − 𝑀 + 𝑦 − 𝑀
1 6 1 6

1
𝑓 𝑥 = [ 1−𝑥 0 + 𝑥−0 −24 ]
6
−24
+ 1−𝑥 1−0 + 𝑥−0 2−
6

1
𝑓 𝑥 = −24𝑥 + 1 − 𝑥 + 6𝑥
6

𝑓 𝑥 = −4𝑥 + 5𝑥 + 1
51
For 𝑖 = 1 in the interval 1 ≤ 𝑥 ≤ 2,

1
𝑓 𝑥 = 𝑥 −𝑥 𝑀 + 𝑥−𝑥 𝑀
6(1)

𝑥 −𝑥 (1) 𝑥−𝑥 (1)


+ 𝑦 − 𝑀 + 𝑦 − 𝑀
1 6 1 6

1
𝑓 𝑥 = [ 2−𝑥 −24 + 𝑥 − 1 276 ]
6

(−24) 276
+ 2−𝑥 2− + (𝑥 − 1) 33 −
6 6

52
𝑓 𝑥 = −4 2 − 𝑥 + 46 𝑥 − 1 − 2 2 − 𝑥 − 13 𝑥 − 1

(∵ 𝑎 − 𝑏 = 𝑎 − 𝑏 − 3𝑎 𝑏 + 3𝑎𝑏 )
𝑓 𝑥 = −4 8 − 𝑥 − 12𝑥 + 6𝑥 + 46 𝑥 − 1 − 3𝑥 + 3𝑥
+6 2 − 𝑥 − 13(𝑥 − 1)
𝑓 𝑥 = −32 + 4𝑥 + 48𝑥 − 24𝑥 + 46𝑥 − 46 − 138𝑥 + 138𝑥
+12 − 6𝑥 − 13x + 13
𝑓 𝑥 = 50𝑥 − 162𝑥 + 167𝑥 − 53

53
For 𝑖 = 2 in the interval 2 ≤ 𝑥 ≤ 3,

1
𝑓 𝑥 = 𝑥 −𝑥 𝑀 + 𝑥−𝑥 𝑀
6(1)

𝑥 −𝑥 (1) 𝑥−𝑥 (1)


+ 𝑦 − 𝑀 + 𝑦 − 𝑀
1 6 1 6

1
𝑓 𝑥 = [ 3−𝑥 276 + 𝑥 − 2 0 ]
6

276
+ 3−𝑥 33 − + 𝑥 − 2 244 − 0
6

(∵ 𝑎 − 𝑏 = 𝑎 − 𝑏 − 3𝑎 𝑏 + 3𝑎𝑏 )

54
𝑓 𝑥 = 27 −𝑥 −27𝑥 + 9𝑥 46 + 𝑥 − 8 − 4𝑥 + 8𝑥 0
+ 3 − 𝑥 −13 + (𝑥 − 2)(244)
𝑓 𝑥 = 1242 − 46𝑥 − 1242𝑥 + 414𝑥 − 39 + 13x + 244x − 488
= −46𝑥 +414𝑥 − 985𝑥 + 715
𝑓 𝑥 = 1242 − 46𝑥 − 1242𝑥 + 414𝑥 − 39 + 13x
+244x − 488
𝑓 𝑥 = −46𝑥 +414𝑥 − 985𝑥 + 715

At 𝑥 = 2.5
𝑓 2.5 = 𝑦 2.5 = −46 2.5 + 414 2.5 − 985 2.5 + 715
= 121.25

55

You might also like