Professional Documents
Culture Documents
Chapter 3A - Interpolation - (11.2020)
Chapter 3A - Interpolation - (11.2020)
Chapter 3A - Interpolation - (11.2020)
1
10/15/2021
1. Polynomial interpolation
2. Newton polynomials
3. Lagrange polynomials
4. Spline Interpolation
5. Least-Squares Regression
6. Using Excel, MATLAB
1. S.C. Chapra, Numerical Methods for Engineers, Mc Graw Hill, 6th Ed., 2010. 4
2. S.C. Chapra, Applied Numerical Methods with MATLAB for Engineers and Scientists, Mc Graw Hill, 3rd Ed., 2012.
2
10/15/2021
3
10/15/2021
𝑓 𝑥 −𝑓 𝑥
𝑓 𝑥 =𝑓 𝑥 + 𝑥−𝑥
𝑥 −𝑥
x y
1 0
2 ???
4 1.386294
6 1.791759
𝑏 =𝑓 𝑥
𝑓 𝑥 −𝑓 𝑥
𝑏 = 𝑓 𝑥 ,𝑥 =
𝑥 −𝑥
𝑓 𝑥 ,𝑥 − 𝑓 𝑥 ,𝑥
𝑏 = 𝑓 𝑥 ,𝑥 ,𝑥 =
𝑥 −𝑥 8
4
10/15/2021
10
5
10/15/2021
11
Fit a third-order
polynomial to the four
points
Use the polynomial to
evaluate ln 2.
12
6
10/15/2021
Fit a third-order
polynomial to the four
points
Use the polynomial to
evaluate ln 2.
13
14
7
10/15/2021
15
16
8
10/15/2021
17
𝑓 𝑥 = 𝐿 𝑥 𝑓 𝑥
𝑥−𝑥
𝐿 𝑥 =
𝑥 −𝑥
18
9
10/15/2021
𝑓 𝑥 = 𝐿 𝑥 𝑓 𝑥
𝑥−𝑥
𝐿 𝑥 =
𝑥 −𝑥
19
20
10
10/15/2021
𝑓 𝑥 = 𝐿 𝑥 𝑓 𝑥
𝑥−𝑥
𝐿 𝑥 =
𝐹𝑖𝑛𝑑 𝑓 2 =? 𝑥 −𝑥
21
third
𝐹𝑖𝑛𝑑 𝑓 2 =?
22
11
10/15/2021
23
24
12
10/15/2021
25
x=[1 4 6 5];
y=[0 1.386294 1.791759 1.609438];
xx = 2;
yint = Lagrange(x,y,xx)
26
13
10/15/2021
• A useful application of Lagrange interpolation is called a table look-up. As the name implies,
this involves “looking-up” an intermediate value from a table. To develop such an algorithm:
1. The table of x and f(x) values are first stored in a pair of one-dimensional arrays.
2. These values are then passed to a function along with the x value you wish to evaluate.
3. The function then performs two tasks:
First, it loops down through the table until it finds the interval within which the unknown
lies.
Then it applies a technique like Lagrange interpolation to determine the proper f(x)
value.
• Develop such a function using a cubic Lagrange polynomial to perform the interpolation.
• For intermediate intervals, this is a nice choice because the unknown will be located in the
interval in the middle of the four points necessary to generate the cubic.
• For the first and last intervals, use a quadratic Lagrange polynomial.
• Also have your code detect when the user requests a value outside the range of x’s.
• For such cases, the function should display an error message. Test your program for f(x)=lnx
using data from x= 1, 2, ... , 10.
27
28
14
10/15/2021
29
30
15
10/15/2021
31
32
16
10/15/2021
33
34
17
10/15/2021
35
36
18
10/15/2021
37
38
19
10/15/2021
39
40
20
10/15/2021
41
x=[1 4 6 5];
y=[0 1.386294 1.791759 1.609438];
p = polyfit(x,y,3)
xx = 2;
yint = polyval(p,xx)
42
21
10/15/2021
43
22
10/15/2021
23