0% found this document useful (0 votes)
473 views22 pages

Module 5

This document provides an overview of curve fitting and interpolation methods, focusing on polynomial interpolation using Lagrange and Newton's polynomials. It outlines key concepts, learning objectives, and examples demonstrating how to estimate unknown values between known data points. The document emphasizes the importance of understanding different interpolation methods for effective data visualization and analysis.

Uploaded by

poldosemon
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)
473 views22 pages

Module 5

This document provides an overview of curve fitting and interpolation methods, focusing on polynomial interpolation using Lagrange and Newton's polynomials. It outlines key concepts, learning objectives, and examples demonstrating how to estimate unknown values between known data points. The document emphasizes the importance of understanding different interpolation methods for effective data visualization and analysis.

Uploaded by

poldosemon
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

ES 221e – Numerical Solution to CE Problem 1

5 Curve Fitting and Interpolation


OVERVIEW
In regression analysis, curve fitting is the process of specifying the model that provides the
best fit to the specific curves in your dataset. Curved relationships between variables are not as
straightforward to fit and interpret as linear relationships. For linear relationships, as you increase
the independent variable by one unit, the mean of the dependent variable always changes by a
specific amount. This relationship holds true regardless of where you are in the observation space.
While the process of estimating unknown values that fall between known values is called
interpolation.

LEARNING OBJECTIVES
At the end of this module, you are expected to:
1. Understand the different interpolation methods
2. Determine and solve fitted line or curve applicable for data visualization
3. Discuss exercises using the steps in solving the value of a function.

KEY TERMS
Polynomial Interpolation – Lagrange and Newton’s Polynomials
Cubic and Quadratic Spline Interpolation
Curve Fitting by Function Approximation
Least Squares Fit

5.1. Polynomial Interpolation – Lagrange and Newton’s Polynomials

LAGRANGE INTERPOLATION

• The process of fitting a polynomial through given data is called polynomial


interpolation.
• Polynomials are often used because they have the property of approximating any
continuous function.

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 2

Polynomial of degree n has n+1 coefficients, that is unknowns to determine. We have n+1
conditions given.

Simplest Case: 2 Points

When n = 2, the problem becomes: Given: x0 ; x1 & f0 ; f1

Find a polynomial of degree one such that

Denote by L0(x) and L1(x) the two first degree polynomials:

These polynomials have the following properties:

So we can rewrite the polynomial that fits the data in the form:

Note: P(x) is the unique linear polynomial passing through the points (x0,f0) and (x1,f1)

The General Case: n + 1 points

Now we generalize the approach to n+1 points.

Given:

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 3

First, we construct the special polynomials Lk(x) so that they have the properties:

These are polynomials that are zero at all points except one.

A polynomial of degree n which is zero at all points except xk is given by

If we want that polynomial to have value one at xk we must divide by its value at xk. Thus,

Then

We would have for k=0,…,n.

Note: P(x) is called the nth Lagrange interpolating polynomial.

EXAMPLE 1:
Find the appropriate Lagrange interpolating polynomial using the table:
x1 x2 x3 x4

f0 f1 f3 f4
We have 4 (0, 0.5, 1, 1.5) points, so the Lagrange
polynomial will be of degree 3.

The basic Lagrange polynomials are:


(𝑥 −𝑥2 )(𝑥 −𝑥3 )(𝑥 −𝑥4 )
For 𝐿𝑜 (𝑥) = (𝑥1 −𝑥2 )(𝑥1 −𝑥3 )(𝑥1 −𝑥4 )
(𝑥 −𝑥1 )(𝑥 −𝑥3 )(𝑥 −𝑥4 )
For 𝐿1 (𝑥) = (𝑥2 −𝑥1 )(𝑥2 −𝑥3 )(𝑥2 −𝑥4 )
(𝑥 −𝑥1 )(𝑥 −𝑥2 )(𝑥 −𝑥4 )
For 𝐿2 (𝑥) =
(𝑥3 −𝑥1 )(𝑥3 −𝑥2 )(𝑥3 −𝑥4 )
(𝑥 −𝑥1 )(𝑥 −𝑥2 )(𝑥 −𝑥3 )
For 𝐿2 (𝑥) = (𝑥4 −𝑥1 )(𝑥4 −𝑥2 )(𝑥4 −𝑥3 )

Using this formula

(𝒙 −𝟎.𝟓)(𝒙 −𝟏)(𝒙 −𝟏.𝟓) 𝒙 (𝒙 −𝟏)(𝒙 −𝟏.𝟓) 𝒙(𝒙 −𝟎.𝟓)(𝒙 −𝟏.𝟓) 𝒙(𝒙 −𝟎.𝟓)(𝒙 −𝟏)
P(x) = (𝟏) (𝟎−𝟎.𝟓)(𝟎−𝟏)(𝟎−𝟏.𝟓)
+ (𝟐) 𝟎.𝟓(𝟎.𝟓−𝟏)(𝟎.𝟓−𝟏.𝟓) + (𝟑) 𝟏(𝟏−𝟎.𝟓)(𝟏−𝟏.𝟓) + (𝟒) 𝟏.𝟓(𝟏.𝟓−𝟎.𝟓)(𝟏.𝟓−𝟏)

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 4

EXAMPLE 2:
Use lagrange Polynomial to estimate f(3) for the given data
x1 x2
x
0.5 1.5
f(0)
f(x) 2
1

We have 2 (0.5 and 1.5) points, so the Lagrange polynomial will be of degree 1.

(𝑥 −𝑥2 ) (𝑥 −1.5)
For 𝐿𝑜 (𝑥) = (𝑥1 −𝑥2 )
𝐿𝑜 (𝑥) = (0.5−1.5)
(𝑥 −𝑥1 ) (𝑥 −0.5)
For 𝐿1 (𝑥) = 𝐿1 (𝑥) =
(𝑥2 −𝑥1 ) (1.5−0.5)

F(3), let x=3


(𝑥 −1.5) (𝑥 −0.5) (3−1.5) (3 −0.5)
P(x) = (𝟏) (0.5−1.5) + (2) (1.5−0.5) P(x) = (𝟏) (0.5−1.5) + (2) (1.5−0.5) = 3.5

Newton’s Polynomials

Newton’s Forward Interpolation


𝑃(𝑃 − 1) 2 𝑃(𝑃 − 1)(𝑃 − 2) 3
𝑦 = 𝑦0 + 𝑃𝛥𝑦0 + (𝛥 𝑦0 ) + (𝛥 𝑦0 )
2! 3!
𝑃(𝑃 − 1)(𝑃 − 2)(𝑃 − 3) 4
+ (𝛥 𝑦0 ) +. . . ..
4!

xj yj Δyj Δ2yj Δ3yj


x0 y0 Δy0 = y1 - y0 Δ2y0 = Δy1 - Δy0 Δ3y0 = Δ2y1 - Δ2y0
x1 y1 Δy1 = y2 - y1 Δ2y1 = Δy2 – Δy1
x2 y2 Δy2 = y3 - y2

EXAMPLE 3:

Find the value of f (1.6) if

x 1 1.4 1.8 2.2


y 3.49 4.82 5.96 6.5

xj yj Δyj Δ2yj Δ3yj


X0 =1 y0 = 3.49 Δy0 = 4.82 – 3.49 Δ2y0 = 1.14 – 1.33 = Δ3y0 = -0.6 – (-0.19) =
=1.33 -0.19 -0.41
X1 =1.4 y1 = 4.82 Δy1 = 5.96-4.82 Δ2y1 = 0.54 – 1.14 =
=1.14 -0.6
X2 =1.8 y2 = 5.96 Δy2 = 6.5 – 5.96 =
0.54
X3 =2.2 y3 = 6.5
𝑥− 𝑥0 1.6− 1.4
𝑃 = ℎ
= 0.4
= 0.5 𝑛𝑜𝑡𝑒: ℎ = 𝑥1 − 𝑥0 = 𝑥2 − 𝑥1 = 𝑥3 − 𝑥2
0.5(0.5 − 1) 0.5(0.5 − 1)(0.5 − 2)
𝑦 = 3.49 + (0.5)(1.33) + (−0.19 ) + (−0.41 ) = 𝟒. 𝟐𝟒𝟏𝟐𝟓
2! 3!

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 5

EXAMPLE 4:

The value of table for x and y

Newton's forward difference table is

The value of x at you want to find the f(x) : x = 1895

h=x1-x0=1901-1891=10
p=(x-x0)/h=(1895-1891)/10=0.4

Newton's forward difference interpolation formula is


𝑃(𝑃−1) 𝑃(𝑃−1)(𝑃−2) 𝑃(𝑃−1)(𝑃−2)(𝑃−3)
𝑦 = 𝑦0 + 𝑃𝛥𝑦0 + 2!
(𝛥2 𝑦0 ) + 3!
(𝛥3 𝑦0 ) + 4!
(𝛥4 𝑦0 ) . . . . ..
0.4(0.4−1) 0.4(0.4−1)(0.4−2)
𝑦 (1895) = 46 + 0.4(20) + 2!
(−5) + 3!
(2) +
0.4(0.4−1)(0.4−2)(0.4−3)
(−3) . . . . ..
4!
𝑦 (1895) = 46 + 8 + 0.6 + 0.128 + 0.1248
𝑦 (1895) = 54.8528

Newton’s Backward Interpolation Formula

𝑃(𝑃 + 1) 2 𝑃(𝑃 + 1)(𝑃 + 2) 3


𝑦(𝑥) = 𝑦𝑛 + 𝑃 ∇𝑦𝑛 + (∇ 𝑦𝑛 ) + (∇ 𝑦𝑛 )
2! 3!
𝑃(𝑃 + 1)(𝑃 + 2)(𝑃 + 3) 4
+ (∇ 𝑦𝑛 )
4!
+. . ..
𝑥 − 𝑥𝑛
𝑃=

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 6

EXAMPLE 5:

x = 1925

Newton's backward difference table is

xj yj ∇yj ∇2yj ∇3yj ∇4yj


X0 y0 = 46 Δy0 = 66 – 46 = Δ2y0 = 15 – 20 = -5 Δ3y0 = -3 – (-5) = ∇4y0 = -1 – 2 = -
=1891 20 2 3
X1 y1 = 66 Δy1 = 81 – 66 Δ y1 = 12 – 15 = -3 Δ3y1 = -4 – (-3) =
2

=1901 =15 -1
X2 y2 = 81 Δy2 = 93 – 81 Δ y0 = 8 – 12 = -4
2

=1911 = 12
X3 y3 = 93 Δy3 = 101 – 93
=1921 =8
X4 = y4 = 101
1931

The value of x at you want to find the f(x):x=1925


ℎ = 𝑥1 − 𝑥0 = 𝑥2 − 𝑥1 = 𝑥3 − 𝑥2
ℎ = 1901 − 1891 = 10
1925 − 1831
𝑃= = −0.6
10
𝑃(𝑃 + 1) 2 𝑃(𝑃 + 1)(𝑃 + 2) 3
𝑦(𝑥) = 𝑦𝑛 + 𝑃 ∇𝑦𝑛 + (∇ 𝑦𝑛 ) + (∇ 𝑦𝑛 )
2! 3!
𝑃(𝑃 + 1)(𝑃 + 2)(𝑃 + 3) 4
+ (∇ 𝑦𝑛 )
4!
−0.6(−0.6 + 1) −0.6(−0.6 + 1)(−0.6 + 2)
𝑦(𝑥) = 101 + (−0.6) (8) + (−4) + (−1)
2! 3!
−0.6(−0.6 + 1)(−0.6 + 2)(−0.6 + 3)
+ (−3)
4!
𝑦(1925) = 101 − 4.8 + 0.056 + 0.1008
𝑦(1925) = 96.8368

Newton’s Divided Difference Interpolation Formula

𝑦(𝑥) = 𝑦0 + (𝑥 − 𝑥0 ) 𝑓[𝑥0 , 𝑥1 ] + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) 𝑓[𝑥0 , 𝑥1 , 𝑥2 ] +. . ..

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 7

EXAMPLE 6:
Find Solution using Newton's Divided Difference Interpolation formula

x = 301

The value of table for x and y

Numerical divided differences method to find solution

Newton's divided difference table is

xj yj 1st Order 2nd Order


X0 y0 = (2.4829 - 2.4771)/4 = 0.0014 - 0.00145 = 0
=300 2.4771 0.00145
X1 y1 = (2.4843 -2.4829)/1 = 0.0014-0.0014 = 0
=304 2.4829 0.0014
X2 y2 = (2.4871- 2.4843)/2 =
=305 2.4843 0.0014
X3 y3 =
=307 2.4871

Note 1st Order = (x1 - x0)/ da ; (x2 - x1)/ db and so on


x1 - x0 = da ; x2-x1= db and so on
The value of x at you want to find the f(x):x=301

𝑦(𝑥) = 𝑦0 + (𝑥 − 𝑥0 ) 𝑓[𝑥0 , 𝑥1 ] + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) 𝑓[𝑥0 , 𝑥1 , 𝑥2 ] +. . ..


𝑦(301) = 2.4771 + (301 − 300) (0.00145) + (301 − 300)(301 − 304) (0)
𝑦(301) = 2.4771 + 1 (0.00145) + 1(−3) (0)
𝑦(301) = 2.47858

5.2 Cubic and Quadratic Spline Interpolation

Cubic spline formula

(𝑥𝑖 − 𝑥)3 (𝑥 − 𝑥𝑖−1 )3 (𝑥𝑖 − 𝑥) ℎ2 (𝑥 − 𝑥𝑖−1 ) ℎ2


𝑓(𝑥) = 𝑀𝑖−1 + 𝑀𝑖 + (𝑦𝑖−1 − 𝑀𝑖−1 ) + (𝑦𝑖 − 𝑀𝑖 )
6ℎ 6ℎ ℎ 6 ℎ 6
→ (1)
6
𝑀𝑖−1 + 4𝑀𝑖 + 𝑀𝑖+1 = 2 (𝑦𝑖−1 − 2𝑦𝑖 + 𝑦𝑖+1 ) → (2)

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 8

EXAMPLE 7:
Calculate Cubic Splines
x0 x1 x2 x3

y0 y1 y2 y3

y(1.5), y'(2)

(𝑥𝑖 − 𝑥)3 (𝑥 − 𝑥𝑖−1 )3 (𝑥𝑖 − 𝑥) ℎ2 (𝑥 − 𝑥𝑖−1 ) ℎ2


𝑓(𝑥) = 𝑀𝑖−1 + 𝑀𝑖 + (𝑦𝑖−1 − 𝑀𝑖−1 ) + (𝑦𝑖 − 𝑀𝑖 )
6ℎ 6ℎ ℎ 6 ℎ 6
→ (1)

6
We have, 𝑀𝑖−1 + 4𝑀𝑖 + 𝑀𝑖+1 = (𝑦 − 2𝑦𝑖 + 𝑦𝑖+1 ) → (2)
ℎ2 𝑖−1
Here h=1,n=3 𝑛𝑜𝑡𝑒: ℎ = 𝑥1 − 𝑥0 = 𝑥2 − 𝑥1 = 𝑥3 − 𝑥2

Note that 𝑀0 = 0 ; 𝑀𝑖 = 0 ; 𝑡ℎ𝑢𝑠, 𝑀3 = 0

Substitute i=1 in equation (2)


6
𝑀𝑖−1 + 4𝑀𝑖 + 𝑀𝑖+1 = (𝑦 − 2𝑦𝑖 + 𝑦𝑖+1 ) → (2)
ℎ2 𝑖−1
6
𝑀1−1 + 4𝑀1 + 𝑀1+1 = (𝑦 − 2𝑦1 + 𝑦1+1 )
12 1−1
≫ 0 + 4𝑀1 + 𝑀2 = 6[1 − 2(5) + 11]

≫ 4𝑀1 + 𝑀2 = 12 → (𝑎)

Substitute i=2 in equation (2)


6
𝑀2−1 + 4𝑀2 + 𝑀2+1 = (𝑦 − 2𝑦2 + 𝑦2+1 )
ℎ2 2−1
6
𝑀1 + 4𝑀2 + 𝑀3 = (𝑦 − 2𝑦2 + 𝑦3 )
12 1
≫ 𝑀1 + 4𝑀2 + 0 = 6[5 − 2(11) + 8]

≫ 𝑀1 + 4𝑀2 = −54

Solving these 2 equations using elimination method


Total Equations are 2

4𝑀1 + 𝑀2 = 12 → (𝑎)

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 9

𝑀1 + 4𝑀2 = −54 → (𝑏)

Select the equations (1) and (2), and eliminate the variable M1

4𝑀1 + 𝑀2 = 12 → 𝑥 1 → 4𝑀1 + 𝑀2 = 12

𝑀1 + 4𝑀2 = −54 → 𝑥 4 → 4𝑀1 + 16𝑀2 = −216

−15𝑀2 = 228 → (3)

Now use back substitution method from (3)


−15𝑀2 = 228

𝑀2 = −15.2

From (2)

𝑀1 + 4𝑀2 = −54

→ 𝑀1 + 4(−15.2) = −54

→ 𝑀1 = 6.8

Solution using Elimination method.

𝑀1 = 6.8 ; 𝑀2 = −15.2

Substitute i=1 in equation (1), we get cubic spline in 1st interval [x0,x1]=[1,2]
(𝑥𝑖 − 𝑥)3 (𝑥 − 𝑥𝑖−1 )3 (𝑥𝑖 − 𝑥) ℎ2 (𝑥 − 𝑥𝑖−1 ) ℎ2
𝑓(𝑥) = 𝑀𝑖−1 + 𝑀𝑖 + (𝑦𝑖−1 − 𝑀𝑖−1 ) + (𝑦𝑖 − 𝑀𝑖 )
6ℎ 6ℎ ℎ 6 ℎ 6
→ (1)

(𝑥1 − 𝑥)3 (𝑥 − 𝑥1−1 )3 (𝑥1 − 𝑥) 12 (𝑥 − 𝑥1−1 ) 12


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

(𝑥1 − 𝑥)3 (𝑥 − 𝑥0 )3 (𝑥1 − 𝑥) 12 (𝑥 − 𝑥0 ) 12


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

(2 − 𝑥)3 (𝑥 − 1)3 (2 − 𝑥) 1 (𝑥 − 1) 1
𝑓1 (𝑥) = (0) + (6.8) + (1 − 𝑥 0) + (5 − 𝑥6.8)
6 6 1 6 1 6
𝑓1 (𝑥) = 1.1333𝑥 3 − 3.4𝑥 2 + 6.2667𝑥 − 3. 𝑓𝑜𝑟 1 ≤ 𝑥 ≤ 2

Substitute i=2 in equation (1), we get cubic spline in 2nd interval [x1,x2]=[2,3]
(𝑥𝑖 − 𝑥)3 (𝑥 − 𝑥𝑖−1 )3 (𝑥𝑖 − 𝑥) ℎ2 (𝑥 − 𝑥𝑖−1 ) ℎ2
𝑓(𝑥) = 𝑀𝑖−1 + 𝑀𝑖 + (𝑦𝑖−1 − 𝑀𝑖−1 ) + (𝑦𝑖 − 𝑀𝑖 )
6ℎ 6ℎ ℎ 6 ℎ 6
→ (1)

(𝑥2 − 𝑥)3 (𝑥 − 𝑥2−1 )3 (𝑥2 − 𝑥) 12 (𝑥 − 𝑥2−1 ) 12


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

(3 − 𝑥)3 (𝑥 − 2)3 (3 − 𝑥) 1 (𝑥 − 2) 1
𝑓2 (𝑥) = (6.8) + (−15.2) + (5 − 𝑥 6.8) + (11 − 𝑥 − 15.2)
6 6 1 6 1 6
𝑓2 (𝑥) = −3.6667𝑥 3 + 25.4𝑥 2 − 51.3333𝑥 + 35.4, 𝑓𝑜𝑟 2 ≤ 𝑥 ≤ 3

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 10

Substitute i=3 in equation (1), we get cubic spline in 3rd interval [x2,x3]=[3,4]
(𝑥3 − 𝑥)3 (𝑥 − 𝑥2 )3 (𝑥2 − 𝑥) ℎ2 (𝑥 − 𝑥2 ) ℎ2
𝑓3 (𝑥) = 𝑀2 + 𝑀2 + (𝑦2 − 𝑀2 ) + (𝑦3 − 𝑀3 )
6ℎ 6ℎ ℎ 6 ℎ 6

(4 − 𝑥)3 (𝑥 − 3)3 (4 − 𝑥) 1 (𝑥 − 3) 1
𝑓3 (𝑥) = (−15.2) + (0) + (11 − 𝑥 − 15.2 ) + (8 − 𝑥 0)
6 6 1 6 1 6
𝑓3 (𝑥) = 2.5333𝑥 3 − 30.4𝑥 2 + 116.0667𝑥 − 132, 𝑓𝑜𝑟 3 ≤ 𝑥 ≤ 4

For y(1.5), 1.5∈[1,2], so substitute x=1.5 in f1(x), we get


𝑓1 (1.5) = 1.1333𝑥 3 − 3.4𝑥 2 + 6.2667𝑥 − 3.

𝑓1 (1.5) = 1.1333(1.5)3 − 3.4(1.5)2 + 6.2667(1.5) − 3

𝑓1 (1.5) = 2.575

For y′(2), 2∈[1,2], so find f ′1(x)

𝑓 ′1 (𝑥) = 3.4𝑥 2 − 6.8x + 6.2667

Now substitute x=2 in f′1(x), we get


𝑓 ′1 (2) = 6.2667

EXAMPLE 8:
Using the same values in example 7. Solve if y(1.5) , y’(3)

For y(1.5), 1.5 is in between of [1,2], so substitute x=1.5 in f1(x), we get

𝑓1 (1.5) = 1.1333𝑥 3 − 3.4𝑥 2 + 6.2667𝑥 − 3.

𝑓1 (1.5) = 1.1333(1.5)3 − 3.4(1.5)2 + 6.2667(1.5) − 3

𝑓1 (1.5) = 2.575

For y′(3), 3 is in the limit of [2,3], so find f ′2(x)

𝑓2 (𝑥) = −3.6667𝑥 3 + 25.4𝑥 2 − 51.3333𝑥 + 35.4

𝑓2 ′(1.5) = −11.0001𝑥 2 + 50.8𝑥 − 51.3333

Now substitute x=3 in f′2(x), we get

𝑓 ′2 (3) = 2.0650

Quadratic Spline Interpolation


In these splines, a quadratic polynomial approximates the data between two consecutive
data points. Given (x0, y0),….,(xn-1 , yn-1) , (xn, yn) fit quadratic splines through the data. The splines
are given by

𝑓(𝑥) = 𝑎1 𝑥 2 + 𝑏1 𝑥 + 𝑐1 , 𝑥0 ≤ 𝑥 ≤ 𝑥1 +

= 𝑎2 𝑥 2 + 𝑏2 𝑥 + 𝑐2 , 𝑥1 ≤ 𝑥 ≤ 𝑥2

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 11

…..
= 𝑎𝑛 𝑥 2 + 𝑏𝑛 𝑥 + 𝑐𝑛 , 𝑥𝑛−1 ≤ 𝑥 ≤ 𝑥𝑛

So how does one find the coefficients of these quadratic splines? There are 3n such coefficients

To find 3n unknowns, one needs to set up 3n equations and then simultaneously solve them.
These 3n equations are found as follows

1. Each quadratic spline goes through two consecutive data points

This condition gives 2n equations as there are n quadratic splines going through two consecutive
data points.

2. The first derivatives of two quadratic splines are continuous at the interior points. For example,
the derivative of the first spline

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 12

Since there are (n −1) interior points, we have (n −1) such equations. So far, the total number of
equations is (2n) + (n −1) = (3n −1) equations. We still then need one more equation. We can
assume that the first spline is linear, that is 0 a1 = This gives us 3n equations and 3n unknowns.
These can be solved by a number of techniques used to solve simultaneous linear equations.

EXAMPLE 9:

The upward velocity of a rocket is given as a function of time as

Table A Velocity as a function of time

a) Determine the value of the velocity at t =16 seconds using quadratic splines.
b) Using the quadratic splines as velocity functions, find the distance covered by the
rocket from t =11s to t =16s.
c) Using the quadratic splines as velocity functions, find the acceleration of the rocket at t
=16s.

Solution
a) Since there are six data points, five quadratic splines pass through them.

𝑣(𝑡) = 𝑎1 𝑡 2 + 𝑏1 𝑡 + 𝑐1 , 0 ≤ 𝑡 ≤ 10
= 𝑎2 𝑡 2 + 𝑏2 𝑡 + 𝑐2 , 10 ≤ 𝑡 ≤ 15
= 𝑎3 𝑡 2 + 𝑏3 𝑡 + 𝑐3 , 15 ≤ 𝑡 ≤ 20
2
= 𝑎4 𝑡 + 𝑏4 𝑡 + 𝑐4 , 20 ≤ 𝑡 ≤ 22.5
2
= 𝑎5 𝑥 + 𝑏5 𝑥 + 𝑐5 , 22.5 ≤ 𝑡 ≤ 30
The equations are found as follows. 1. Each quadratic spline passes through two consecutive data
points.

𝑎1 𝑡 2 + 𝑏1 𝑡 + 𝑐1 𝑝𝑎𝑠𝑠𝑒𝑠 𝑡ℎ𝑟𝑜𝑢𝑔ℎ 𝑡 = 0 𝑎𝑛𝑑 𝑡 = 10


𝑎1 (0)2 + 𝑏1 (0) + 𝑐1 = 0 → 1
𝑎1 (110)2 + 𝑏1 (0) + 𝑐1 = 227.04 → 2

𝑎2 𝑡 2 + 𝑏2 𝑡 + 𝑐2 𝑝𝑎𝑠𝑠𝑒𝑠 𝑡ℎ𝑟𝑜𝑢𝑔ℎ 𝑡 = 10 𝑎𝑛𝑑 𝑡 = 15


𝑎2 (10)2 + 𝑏2 (10) + 𝑐2 = 227.04 → 3
𝑎2 (15)2 + 𝑏2 (15) + 𝑐2 = 362.78 → 4

𝑎3 𝑡 2 + 𝑏3 𝑡 + 𝑐3 𝑝𝑎𝑠𝑠𝑒𝑠 𝑡ℎ𝑟𝑜𝑢𝑔ℎ 𝑡 = 15 𝑎𝑛𝑑 𝑡 = 20


𝑎3 (15)2 + 𝑏3 (15) + 𝑐3 = 362.78 → 5
𝑎3 (20)2 + 𝑏3 (20) + 𝑐3 = 517.35 → 6

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 13

𝑎4 𝑡 2 + 𝑏4 𝑡 + 𝑐4 𝑝𝑎𝑠𝑠𝑒𝑠 𝑡ℎ𝑟𝑜𝑢𝑔ℎ 𝑡 = 20 𝑎𝑛𝑑 𝑡 = 22.5


𝑎4 (20)2 + 𝑏4 (20) + 𝑐4 = 517.35 → 7
2
𝑎4 (22.5) + 𝑏4 (22.5) + 𝑐4 = 602.97 → 8

𝑎5 𝑡 2 + 𝑏5 𝑡 + 𝑐5 𝑝𝑎𝑠𝑠𝑒𝑠 𝑡ℎ𝑟𝑜𝑢𝑔ℎ 𝑡 = 22.5 𝑎𝑛𝑑 𝑡 = 30


𝑎5 (22.5)2 + 𝑏5 (22.5) + 𝑐5 = 602.97 → 9
2
𝑎5 (30) + 𝑏5 (30) + 𝑐5 = 901.67 → 10

2. Quadratic splines have continuous derivatives at the interior data points.


At t = 10
2𝑎1 (10) + 𝑏1 − 2𝑎2 (10) − 𝑏2 = 0 → 11
At t = 15
2𝑎2 (15) + 𝑏2 − 2𝑎3 (15) − 𝑏3 = 0 → 12
At t = 20
2𝑎3 (20) + 𝑏3 − 2𝑎4 (20) − 𝑏4 = 0 → 13
At t = 22.5
2𝑎4 (22.5) + 𝑏4 − 2𝑎5 (22.5) − 𝑏5 = 0 → 14

3. Assuming the first spline 1 1 2 1 a t + b t + c is linear,


𝑎1 = 0 → 15

Combining Equation (1) – (15) in matrix form gives

Combining Equation (1) – (15) in matrix form gives

Therefore, the splines are given by

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 14

𝑣(𝑡) = 22.704𝑡, 0 ≤ 𝑡 ≤ 10
= 0.8888𝑡 2 + 4.982𝑡 + 88.88 10 ≤ 𝑡 ≤ 15
= −0.135𝑡 2 + 35.66𝑡 − 141.61 15 ≤ 𝑡 ≤ 20
= 1.6048𝑡 2 − 33.596𝑡 + 554.55 20 ≤ 𝑡 ≤ 22.5
= 0.20889𝑡 2 + 28.86𝑡 − 152.13 22.5 ≤ 𝑡 ≤ 30

At t =16s
𝑣(16) = −0.1356(16)2 + 35.66(16) − 141.61
= −394.24 𝑚/𝑠

b) The distance covered by the rocket between 11 and 16 seconds can be calculated as
16
𝑠(16) − 𝑠(11) = ∫11 𝑣(𝑡)𝑑𝑡

But since the splines are valid over different ranges, we need to break the integral accordingly as
𝑣(𝑡) = 0.8888𝑡 2 + 4.982𝑡 + 88.88 10 ≤ 𝑡 ≤ 15
2
= −1356𝑡 + 35.66𝑡 − 141.61 15 ≤ 𝑡 ≤ 20
16 15 16
∫ 𝑣(𝑡)𝑑𝑡 = ∫ 𝑣(𝑡)𝑑𝑡 + ∫ 𝑣(𝑡)𝑑𝑡
11 11 15

𝑠(16) − 𝑠(11)
15
= ∫ (0.8888𝑡 2 + 4.982𝑡 + 88.88 )𝑑𝑡
11
16
+ ∫ (−1356𝑡 2 + 35.66𝑡 − 141.61)𝑑𝑡
15
15 16
𝑡3 𝑡2 𝑡3 𝑡2
= [0.8888 + 4.98 + 88.88𝑡] + [−0.1356 + 35.66 − 141.61𝑡]
3 2 11
3 2 15
= 1217.35 + 378.53
= 1595.9 𝑚

c) What is the acceleration at t = 16 ?

5.3. Curve Fitting by Function Approximation

Curve fitting: the process of finding the equation of the curve which best fits the given values and
is most suitable for predicting the unknown values.

Function approximation: The goal would be to come up with an approximating functional form
using a finite set of data points.

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 15

Methods in Solving
1. Method of Group averages
2. Methods of moments

Method of group of averages

Algorithm:
1. Line to be fitted for the data is y= ax + b; where a and b needs to be calculated.
2. Divide the set of data into two groups.
3. Compute the averages of x's and y's in two groups.
4. Substitute it to the line y = ax + b then solve for the value of a and b.

EXAMPLE 10:

Fit a straight line y = ax² + bx + c to the ff. data

x 0 2 4 6 8 10
y 6 9 12 14 17 20

Let y = ax² bx + c

First, we have to convert it into standard form; y=ax + b form

1. take any point in the data, let say (2,9) as a point on the curve
y=ax²+bx+c eq.(1)
9=a(2²) +b(2)+c
9=4a+2b+c eq. (2)

[Link] eq.(1) to eq.(2), we get;


(y-9)/(x-2) = a(x+2)+b

3. Which is in the form of Y=aX+ b eq(3)


where Y=(y-9/x-2) and X=X+2

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 16

x y X=x+2 Y=(y-9/x-2)
0 6 2 1.5
2 9 4 0
4 12 6 1.5
total 12 3

The averages of x's and y's in two group are:


X1 = 12/3 = 4 X2 = 30/3 = 10
Y1 = 3/3 =1 Y2 = 3.965/3 = 1.321

Substituting these averages in Y=aX+b eq.(3), we have:


4a + b = 1
10a + b = 1.321
Solving for a and b, we get;
A = 0.0535 , b = -0.786
To solve for c, substitute a and b to eq.(2)
9=4a+2b+c
9=4(.0535) +2( -0.786)+c
c = 7. 214
So the required best fit for the data is
y = 0.0535x2 + 0.786x +7.214
y = 0.0535(6)2 + 0.786(6) +7.214
y = 13.856

Method of Moments
1. Let (x1 , y1), (x2 , y2), (x3 , y3) …. (xn , yn-1) be n set of points or observation such that x is
equally spaced. i.e x2 – x1 = x3 – x2

2. Let h = xn – xn-1

3. Solve for the moment of y or (μ);


μm = ℎ ∑ 𝑥 𝑚−1 𝑦
4. Let y = f(x) is a given curve.
5. Solve for the moment of calculated value or (y);
𝑥 − ℎ/2
𝛾𝑚 = ∫𝑥 𝑛− ℎ/2 𝑥 𝑚−1 𝑓(𝑥)𝑑𝑥
1
6. Assume μm = 𝛾𝑚
𝑥𝑛 − ℎ/2
ℎ ∑ 𝑥 𝑚−1 𝑦 = ∫ 𝑥 𝑚−1 𝑓(𝑥)𝑑𝑥
𝑥1 − ℎ/2

EXAMPLE 11:
Fit a straight line to the ff. data

x 1 2 3 4
y 16 19 23 26

Let the equation of the straight line: y = a+ bx


h = xn – xn-1 (let say n = 2)
h = 2 -1

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 17

h=1
For moment of y; μm = ℎ ∑ 𝑥 𝑚−1 𝑦
The first moment; μ1 =1∑ 𝑥 1−1 𝑦
μ1 =84
The second moment; μ2 =1∑ 𝑥 2−1 𝑦
μ2 =227
Let y = f(x)
For the moment of the calculated value (y);
𝑥 − ℎ/2
𝛾𝑚 = ∫𝑥 𝑛− ℎ/2 𝑥 𝑚−1 𝑓(𝑥)𝑑𝑥
1
The first moment:
𝑥 − 1/2
𝛾1 = ∫𝑥 4− 1/2 𝑥 1−1 𝑓(𝑥)𝑑𝑥
1
𝛾1 = 4𝑎 + 10𝑏 𝑒𝑞 1
The second moment;
𝑥4 − 1/2
𝛾2 = ∫ 𝑥 2−1 𝑓(𝑥)𝑑𝑥
𝑥1 − 1/2
𝛾1 = 10𝑎 + 30.33𝑏 𝑒𝑞 2
Assume μm = 𝛾𝑚
4𝑎 + 10𝑏 = 84
10𝑎 + 30.33𝑏 = 227
By solving; a = 13.2 and b = 3.19
y = a + bx
y = 13.02 + 3.19x

5.4 Least Squares Fit (LSF)

Linear Regression using LSF

EXAMPLE 12:

Write a linear equation that best fits the data in the table shown below:

x 1 2 3 4 5 6 7
y 1.5 3.8 6.7 9.0 11.2 13.6 16

x y xy x2
1 1.5 1.5 1

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 18

2 3.8 7.6 4
3 6.7 20.1 9
4 9.0 36 16
5 11.2 56 25
6 13.6 81.6 36
7 16 112 49
total 28 61.8 314.8 140

∑ 𝑥 = 28 ∑ 𝑦 = 61.8 ∑ 𝑥𝑦 = 314.8 ∑ 𝑥 2 = 140

n=7

y = mx + b

𝑛 ∑ 𝑥𝑦 −∑ 𝑥 ∑ 𝑦
m= 𝑛 ∑ 𝑥 2 −(∑ 𝑥)^2

7(314.8)−(28)(61.8)
m= = 473.2/196 = 2.4142857
7(140)−(28)2

∑𝑦 − 𝑚∑𝑥
𝑏 =
𝑛
61.8 −(2.4142857)(28)
𝑏 = = − 0.828571
7

Now we have the equation of a slope

y = 2.414x – 0.83

Now looking back to the table to check if the values solved are correct.

x 1 2 3 4 5 6 7
y 1.5 3.8 6.7 9.0 11.2 13.6 16

y = 2.414x – 0.83

for x = 1
y = 2.414(1) – 0.83 = 1.58, not too far away from 1.5 Correct

for x = 2
y = 2.414(2) – 0.83 = 3.99, not too far away from 3.8 Correct

for x = 3
y = 2.414(3) – 0.83 = 6.414, not too far away from 6.7 Correct

for x = 4
y = 2.414(4) – 0.83 = 8.8, not too far away from 9.0 Correct

for x = 5
y = 2.414(5) – 0.83 = 11.24, not too far away from 11.2 Correct

for x = 6
y = 2.414(6) – 0.83 = 13.65, not too far away from 13.6 Correct

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 19

for x = 7
y = 2.414(7) – 0.83 = 16.07, not too far away from 16 Correct

Curve Fitting using LSF

EXAMPLE 13:
Find the curve of the best fit of a parabola y = aebx to the following data by using least square
method.

x 1 5 7 9 17
y 10 15 12 15 21

𝑙𝑜𝑔𝑦 = 𝑙𝑜𝑔𝑎 + 𝑙𝑜𝑔𝑒 𝑏𝑥


𝑙𝑜𝑔𝑦 = 𝑙𝑜𝑔𝑎 + 𝑏𝑥𝑙𝑜𝑔𝑒
𝑦 = 𝐴 + 𝐵𝑥
∑ 𝑌 = 𝑛𝐴 + 𝐵 ∑ 𝑥 𝑒𝑞(1)

∑ 𝑥𝑌 = 𝐴 ∑ 𝑥 + 𝐵 ∑ 𝑥 2 𝑒𝑞 (2)

x y Y = logy x2 𝑥𝑌
1 10 1 1 1
5 15 1.18 25 5.9
7 12 1.08 49 7.56
9 15 1.18 81 10.62
12 21 1.32 144 15.84
∑ 𝑥 = 34 ∑ 𝑌 = 5.76 ∑ 𝑥 2 = 300 ∑ 𝑥𝑌 = 40. 92

n=5

∑ 𝑌 = 𝑛𝐴 + 𝐵 ∑ 𝑥

5.76 = 5𝐴 + 24𝐵 𝑒𝑞 𝐴

∑ 𝑥𝑌 = 𝐴 ∑ 𝑥 + 𝐵 ∑ 𝑥 2

40.92 = 34𝐴 + 300𝐵 𝑒𝑞 𝐵

We have two equations, two unknowns. We can our calculator to determine the values by following
these steps.

1. Press MODE(SETUP) key, then select 5 EQN by pressing 5.


2. Type 1 (anX +bnY = cn)
3. Type the equations
Note; When typing the equation you must know what is A, B and C.
In equation 1, 5A= A , 24B =B and 5.76 = C
In equation 2, 34A= A , 300B =B and 40.92 = C
4. press equal when done typing to get the values.

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 20

A = 0.9788 B=0.02546

Looking back in this equation,

𝑙𝑜𝑔𝑦 = 𝑙𝑜𝑔𝑎 + 𝑏𝑥𝑙𝑜𝑔𝑒


𝐴 = 𝑙𝑜𝑔𝑎

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 21

𝑎 = 𝑎𝑛𝑡𝑖𝑙𝑜𝑔𝐴
𝑖𝑛 𝑚𝑜𝑑𝑒 1 𝑜𝑓 𝑦𝑜𝑢𝑟 𝑐𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑜𝑟, 𝑝𝑟𝑒𝑠𝑠 𝑠ℎ𝑖𝑓𝑡 𝑙𝑜𝑔.
𝑎 = 100.9788
𝑎 = 9.5499

𝐵 = 𝑙𝑜𝑔𝑏
𝑏 = 𝑎𝑛𝑡𝑖𝑙𝑜𝑔𝐵
𝑏 = 100.025446
𝑏 = 1.06034

y = aebx

y = 9.95e1.06x

CHECK YOUR UNDERSTANDING EXERCISES

INSTRUCTIONS: Answer the following questions. Write your answer in your notebook. Please
observe cleanliness to your work.
1) Find solution using Lagrange’s Interpolation if x = 2.7

x 2 2.5 3
y 0.69315 0.91629 1.09861

2) Find Solution using Newton’s Forward Difference formula


x 0 1 2 3
y 1 0 1 10

3) Find Solution using Newton’s Backward Difference formula

x 0 1 2 3
y 1 0 1 10

4) Find Solution using Newton’s Divided Difference formula


x 2 2.5 3
y 0.69315 0.91629 1.09861

5) Fit the parabola y = a + bx + cx2


x 0 1 2 3 4
y 1 1.8 1.3 2.5 6.3
6) A trunnion is cooled 80°F to − 108°F. Given below is the table of the coefficient of thermal
expansion vs. temperature. Determine the value of the coefficient of thermal expansion at
T=−14°F using quadratic spline interpolation.

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer
ES 221e – Numerical Solution to CE Problem 22

SUGGESTED READINGS

Newton's Divided Difference Interpolation formula (Numerical Interpolation) Formula & Examples
([Link])

Spline Interpolation Method Mechanical Engineering Majors Authors: Autar Kaw, Jai Paul

REFERENCES

Student Solutions Manual and Study Guide for Numerical Analysis, 9th Edition
Richard L. Burden, Cengage Learning, 2011

Numerical Mathematics and Computing, 7th Edition


Ward Cheney, Cengage Learning, 2013

Numerical Solution of Partial Differential Equations, 3rd Edition


Granville Sewell, Wspc, 2014

Differential Equations, 4th Edition


Paul Blanchard, Robert L. Devaney, Glen R. Hall, Cengage Learning, 2011

Engr. Michael John T. Guillermo, RME


Subject Teacher/ Special Lecturer

You might also like