You are on page 1of 23

10/15/2021

HCM CITY UNIVERSITY OF TECHNOLOGY AND EDUCATION


Faculty of High Quality Learning

A/Prof. Pham Huy Tuan

OCTOBER 15, 2021

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

 Estimate intermediate values between precise data points.


 Polynomial interpolation

(a) first-order (b) Second (c) third-order


(linear) order (cubic)
connecting two (parabolic) connecting
points connecting four points.
three points
5

 The simplest form of interpolation is to connect two data


points with a straight line
𝑓 𝑥 −𝑓 𝑥
𝑓 𝑥 =𝑓 𝑥 + 𝑥−𝑥
𝑥 −𝑥

 The notation f1(x) designates a


first order interpolating
polynomial.
 In general, the smaller the
interval between the data
points, the better the
approximation

3
10/15/2021

 Estimate the natural logarithm of 2 using linear interpolation

𝑓 𝑥 −𝑓 𝑥
𝑓 𝑥 =𝑓 𝑥 + 𝑥−𝑥
𝑥 −𝑥

x y
1 0
2 ???
4 1.386294
6 1.791759

 Exact value: ln(2)=0.6931472

 The simplest form of interpolation is to connect two data points with a


straight line
 A strategy for improving the estimate is to introduce some curvature
into the line connecting the points.
 If 3 data points are available, this can be accomplished with a second-
order polynomial

𝑓 𝑥 =𝑏 +𝑏 𝑥−𝑥 +𝑏 𝑥−𝑥 𝑥−𝑥

𝑏 =𝑓 𝑥

𝑓 𝑥 −𝑓 𝑥
𝑏 = 𝑓 𝑥 ,𝑥 =
𝑥 −𝑥

𝑓 𝑥 ,𝑥 − 𝑓 𝑥 ,𝑥
𝑏 = 𝑓 𝑥 ,𝑥 ,𝑥 =
𝑥 −𝑥 8

4
10/15/2021

 Fit a second-order polynomial to the


three points
 Use the polynomial to evaluate ln 2.

 The preceding analysis can be generalized to fit an nth-order


polynomial to n + 1 data points:

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

 Similar to the Taylor series expansion


 The truncation error for the Taylor series

 For an nth-order interpolating polynomial

15

16

8
10/15/2021

17

 The Lagrange interpolating polynomial is simply a reformulation of the


Newton polynomial that avoids the computation of divided differences

𝑓 𝑥 = 𝐿 𝑥 𝑓 𝑥

𝑥−𝑥
𝐿 𝑥 =
𝑥 −𝑥

18

9
10/15/2021

 The Lagrange interpolating polynomial is simply a reformulation of the


Newton polynomial that avoids the computation of divided differences

𝑓 𝑥 = 𝐿 𝑥 𝑓 𝑥

𝑥−𝑥
𝐿 𝑥 =
𝑥 −𝑥

19

20

10
10/15/2021

𝑓 𝑥 = 𝐿 𝑥 𝑓 𝑥

𝑥−𝑥
𝐿 𝑥 =
𝐹𝑖𝑛𝑑 𝑓 2 =? 𝑥 −𝑥

21

third

𝐹𝑖𝑛𝑑 𝑓 2 =?

22

11
10/15/2021

 Use the interpolation Lagrange polynomial


to study a trend analysis problem
associated with a falling parachutist.
Estimate the velocity of the parachutist at
t= 10 s.

23

 Use the interpolation Lagrange polynomial


to study a trend analysis problem
associated with a falling parachutist.
Estimate the velocity of the parachutist at
t= 10 s.

4th order 3rd order

2nd order 1st order

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

 Apply lower-order polynomials


to subsets of data points. Such
connecting polynomials are
called spline functions.
 The spline usually provides a
superior approximation of the
behavior of functions that have
local, abrupt changes.

28

14
10/15/2021

29

30

15
10/15/2021

 The simplest connection


between two points is a
straight line.

where mi is the slope of the straight line


connecting the points:

31

 The objective in quadratic splines is


to derive a second-order
polynomial for each interval
between data points.

 The polynomial for each interval


can be represented generally as:

32

16
10/15/2021

 There are n intervals and, consequently, 3n unknown constants.


 3n equations or conditions are required to evaluate the unknowns.
1. The function values of adjacent polynomials must
be equal at the interior knots.

2. The first and last functions must pass through the


end points.

3. The first derivatives at the interior knots must be


equal.

4. Assume that the second derivative is zero at the


first point.

33

 There are n intervals and, consequently, 3n unknown constants.


 3n equations or conditions are required to evaluate the unknowns.
1. The function values of adjacent polynomials must
be equal at the interior knots.

2. The first and last functions must pass through the


end points.

3. The first derivatives at the interior knots must be


equal.

4. Assume that the second derivative is zero at the


first point.

34

17
10/15/2021

 Fit quadratic splines to the data used in Table 18.1.


 Use the results to estimate the value at x = 5.

35

 The objective in cubic splines is to derive a third-order polynomial for each


interval between knots.

 4n conditions are required to evaluate the unknowns


1) The function values must be equal at the interior knots (2n - 2 conditions)
2) The first and last functions must pass through the end points (2 conditions).
3) The first derivatives at the interior knots must be equal (n - 1 conditions).
4) The second derivatives at the interior knots must be equal (n - 1 conditions).
5) The second derivatives at the end knots are zero (2 conditions).

36

18
10/15/2021

 An alternative technique that


requires the solution of only n - 1
equations.
 The cubic equation for each
interval

 This equation contains only two unknowns—the second derivatives at the


end of each interval.

37

38

19
10/15/2021

39

40

20
10/15/2021

% Dùng lệnh CFTOOL


x=[1 4 5 6];
y=[0 1.386294 1.609438 ...
1.791759];
cftool
y
2

y = 0,0079x3 - 0,1384x2 + 0,9889x - 0,8584


1,5
% Dùng lệnh POLYFIT,
1 POLYVAL
x=[1 4 5 6];
0,5
y=[0 1.386294 1.609438 ...
0 1.791759];
0 1 2 3 4 5 6 7
n=3;
-0,5
[p,S] = polyfit(x,y,n);
xx=2;
yx = polyval(p,xx);

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

 The interpolation methods for one-dimensional problems can be


extended to multidimensional interpolation

First, we can hold the y value fixed and apply one-


dimensional linear interpolation in the x
direction. Using the Lagrange form:

43

22
10/15/2021

23

You might also like