Lecture 9 - Function Approximation and Interpolation
Lecture 9 - Function Approximation and Interpolation
CE 25
Mathematical Methods
in Civil Engineering II Function
Approximation
and Interpolation
ENGR. MATTHEW TRAVIS ALCANTARA
Instructor
Institute of Civil Engineering
University of the Philippines Diliman
Interpolation
Function Approximation
𝑓0 = 𝑓 𝑥0 𝑓1 = 𝑓 𝑥1 ⋯ 𝑓𝑛 = 𝑓 𝑥𝑛
Find 𝒑𝒏(𝒙) such that
𝑝𝑛 𝑥0 = 𝑓0 𝑝𝑛 𝑥1 = 𝑓1 ⋯ 𝑝𝑛 𝑥𝑛 = 𝑓𝑛
CASE 1
Given a set of nodes {𝑥𝑖, 0 ≤ 𝑖 ≤ 𝑛}, find the polynomial 𝒑𝒏(𝒙) of
degree less than or equal to 𝑛 such that
𝒑𝒏 𝒙𝒊 = 𝒚𝒊 , 𝟎≤𝒊≤𝒏
Interpolation Polynomial
CASE 2
Given a set of nodes {𝑥𝑖, 0 ≤ 𝑖 ≤ 𝑛} and a continuous function 𝑓(𝑥), find
the polynomial 𝒑𝒏(𝒙) of degree less than or equal to 𝑛 such that
𝒑𝒏 𝒙𝒊 = 𝒇 𝒙𝒊 , 𝟎≤𝒊≤𝒏
Polynomial Approximation
3𝑥 2 + 2𝑥 − 7 𝑤ℎ𝑒𝑛 𝑥 = −3 𝑔 𝑥 = 𝐴𝑥 3 + 𝐵𝑥 2 + 𝐶𝑥 + 𝐷 𝑎𝑥 2
න 𝑎 𝑑𝑥 = 𝑎𝑥 න 𝑎𝑥 𝑑𝑥 =
𝑔′ 𝑥 = 3𝐴𝑥 2 + 2𝐵𝑥 + 𝐶 2
3(−3)2 +2 −3 − 7 𝑔′′ 𝑥 = 6𝐴𝑥 + 2𝐵
= 27 − 6 − 7 𝑎𝑥 3 𝑎𝑥 4
𝑔′′′ 𝑥 = 6𝐴 2
න 𝑎 𝑥 𝑑𝑥 = 3
න 𝑎𝑥 𝑑𝑥 =
= 14 3 4
𝑝𝑛 𝑥𝑖 = 𝑦𝑖 , 0≤𝑖≤𝑛
for a given set of data values {𝑦𝑖 }; or
𝑝𝑛 𝑥𝑖 = 𝑓(𝑥𝑖 ), 0≤𝑖≤𝑛
for a given function 𝑓.
Interpolation
Methods
Direct Method | Lagrange
Interpolation | Newton’s Divided
Difference Method
CE 25
Mathematical Methods in Civil Engineering II
Function Approximation and Interpolation
Direct Method
Given 𝑛 + 1 data points (𝑥𝑜, 𝑦𝑜), (𝑥1, 𝑦1), … , (𝑥𝑛, 𝑦𝑛), pass a
polynomial of order 𝑛 through the data as
𝑦 = 𝑎𝑜 + 𝑎1 𝑥 + ⋯ + 𝑎𝑛 𝑥 𝑛
where 𝑎𝑜, 𝑎1, … , 𝑎𝑛 are real constants
Example 9.1
t (sec) v (m/s)
The upward velocity of a rocket is given 0 0
as a function of time. Find the velocity at 10 227.04
t = 16 seconds using the direct method
15 362.78
for quadratic interpolation. Use the
velocity corresponding to t = 10, 15, and 20 517.35
20 seconds. 22.5 602.97
30 901.67
Lagrange Interpolation
Given (𝑥𝑜, 𝑓𝑜), (𝑥1, 𝑓1), … , (𝑥𝑛, 𝑓𝑛) with arbitrarily spaced 𝑥𝑖, each
𝑓𝑗 is multiplied by a polynomial that is equal to 1 at 𝒙𝒋 and 0 at
the other nodes, and summing these 𝑛 + 1 polynomials will
serve as the interpolation polynomial.
*This method is useful in Numerical
Differentiation and Integration.
𝑥 − 𝑥1 𝑥 − 𝑥𝑜
𝑝1 𝑥 = 𝑓𝑜 + 𝑓1
𝑥𝑜 − 𝑥1 𝑥1 − 𝑥𝑜
Example 9.2
Compute ln 9.2 from ln 9.0 = 2.1972, ln 9.5 = 2.2513 by linear
Lagrange interpolation and determine the relative error using
ln 9.2 = 2.2192
Given nodes: Linear Lagrange polynomial:
(𝑥𝑜 , 𝑓𝑜 ) = 9.0, 2.1972 (𝑥1 , 𝑓1 ) = 9.5, 2.2513 𝑥 − 𝑥1 𝑥 − 𝑥𝑜
𝑝1 𝑥 = 𝑓 + 𝑓
𝑥𝑜 − 𝑥1 𝑜 𝑥1 − 𝑥𝑜 1
𝑥 − 9.5 𝑥−9
𝑝1 𝑥 = × 2.1972 + × 2.2513
9 − 9.5 9.5 − 9
9.2 − 9.5 9.2 − 9
𝑝1 9.2 = × 2.1972 + × 2.2513 = 𝟐. 𝟐𝟏𝟖𝟖𝟒
9 − 9.5 9.5 − 9
𝑥𝑒 − 𝑥𝑎 |2.21884 − 2.2192|
𝜖𝑟 = = × 100% = 𝟎. 𝟎𝟏𝟔%
𝑥𝑒 2.2192
𝒑𝟐 𝒙 = 𝑳𝒐 𝒙 𝒇𝒐 + 𝑳𝟏 𝒙 𝒇𝟏 + 𝑳𝟐 𝒙 𝒇𝟐
with 𝐿𝑜(𝑥𝑜) = 1, 𝐿1(𝑥1) = 1, 𝐿2(𝑥2) = 1, and
𝐿𝑜(𝑥1) = 𝐿𝑜(𝑥2) = 𝐿1(𝑥𝑜) = 0, etc.
(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 )
𝑳𝒐 𝒙 =
(𝒙𝒐 − 𝒙𝟏 )(𝒙𝒐 − 𝒙𝟐 )
(𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟐 )
𝑳𝟏 𝒙 =
(𝒙𝟏 − 𝒙𝒐 )(𝒙𝟏 − 𝒙𝟐 )
(𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 )
𝑳𝟐 𝒙 =
(𝒙𝟐 − 𝒙𝒐 )(𝒙𝟐 − 𝒙𝟏 )
Example 9.3
Compute ln 9.2 from ln 9.0 = 2.1972 , ln 9.5 = 2.2513 , ln 11.0 = 2.3979 by quadratic
Lagrange interpolation and determine the relative error using ln 9.2 = 2.2192
Given nodes:
(𝑥𝑜 , 𝑓𝑜 ) = 9.0, 2.1972 (𝑥1 , 𝑓1 ) = 9.5, 2.2513 (𝑥2 , 𝑓2 ) = 11.0, 2.3979
𝑥 − 9.5 𝑥 − 11
𝑝2 𝑥 = × × 2.1972
9 − 9.5 9 − 11 𝑝2 9.2 = 𝟐. 𝟐𝟏𝟗𝟏𝟓𝟒
𝑥−9 𝑥 − 11
+ × × 2.2513 |2.219154 − 2.2192|
9.5 − 9 9.5 − 11 𝜖𝑟 = × 100%
2.2192
𝑥−9 𝑥 − 9.5 𝜖𝑟 = 𝟎. 𝟎𝟎𝟐𝟏%
+ × × 2.3979
11 − 9 11 − 9.5
where 𝐿𝑘(𝑥𝑘) = 1 and 𝐿𝑘 is 0 at the other nodes, and 𝐿𝑘’s are independent
of the function 𝑓 to be interpolated.
Note:
𝑙𝑜 𝑥 = (𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) ⋯ (𝑥 − 𝑥𝑛 )
𝑙𝑘 𝑥 = (𝑥 − 𝑥𝑜 ) ⋯ (𝑥 − 𝑥𝑘−1 )(𝑥 − 𝑥𝑘+1 ) ⋯ (𝑥 − 𝑥𝑛 )
𝑙𝑛 𝑥 = (𝑥 − 𝑥𝑜 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) ⋯ (𝑥 − 𝑥𝑛−1 )
𝑓[𝑥0 ] 𝑓[𝑥0 , 𝑥1 ]
For second degree polynomial, 𝑝2 𝑥 = 𝑝1 𝑥 + 𝑎2 𝑥 − 𝑥0 𝑥 − 𝑥1
Divided Difference! 𝑓 𝑥2 −𝑓 𝑥1
−
𝑓 𝑥1 −𝑓 𝑥0
𝑥2 −𝑥1 𝑥1 −𝑥0
𝑎2 =
𝑥2 −𝑥0
𝑓[𝑥0 , 𝑥1 , 𝑥2 ]
CE 25: Mathematical Methods in CE II
21
Function Approximation and Interpolation
Example 9.4
Compute ln 9.2 from the table using Newton’s divided difference
method. Determine the relative error using ln 9.2 = 2.2192.
𝑥 𝒍𝒏 𝒙
8 2.07944
9 2.197225
9.5 2.251292
11 2.397895
Example 9.4
Compute ln 9.2 from the table using Newton’s divided difference method.
|2.219208 − 2.2192|
𝜖𝑟 = × 100 = 𝟎. 𝟎𝟎𝟎𝟑𝟔%
2.2192
END
Any questions?
CE 25
Mathematical Methods in Civil Engineering II
SEE YOU NEXT MEETING!
ICE 319