TE Mechanical-Numerical Methods & Optimization - Unit 05

Download as pdf or txt
Download as pdf or txt
You are on page 1of 73

Inverse Interpolation

Compiled by
Dr. Shyam Arjun Sonawane
Associate Professor, Mechanical Engineering
Government College of Engineering & Research, Avasari (Kh)
What is Inverse Interpolation ?
• Given (x0,y0), (x1,y1), …… (xn,yn), find the value of ‘x’ at a value of ‘y’
that is not given.
Interpolation: Lagrange formula
• We have been finding the value of y corresponding to a certain value of
x from a given set of values of x and y by using the Lagrange formula
given by
yg=(y0)(L0) + (y1)(L1) + (y2)(L2) +…………+(Yn-1)(Ln-1)
• L0 = (xg − x1) (xg − x2)……. (xg − xn-1)/ (x0 − x1 ) (x0 − x2 ) ……. (x0 − xn-1 )
• L1 = (xg − x0) (xg − x2)……. (xg − xn-1)/ (x1 − x0 ) (x1 − x2 ) ……. (x1 − xn-1 )
• L2 = (xg − x0) (xg − x1)……. (xg − xn-1)/ (x2 − x0 ) (x2 − x1 ) ……. (x2− xn-1 )
• ……………………………………………………………………………………………….
• Ln-1 = (xg − x0) (xg − x1)……. (xg − xn-2)/ (xn-1 − x0 ) (xn-1 − x1) ……. (xn-1 − xn-2 )
Inverse Interpolation: Lagrange formula
• On the other hand, the process of estimating the value of x for a
value of y is called inverse interpolation.

• When the values of y are unequally spaced, Lagrange’s method is


used

• and when the values of y are equally spaced, Newton’s forward


difference formula or iterative method can be used.
Inverse Interpolation: Lagrange formula…cont
• Lagrange’s formula for inverse interpolation is used when we are required
to find the value of x corresponding to a certain value of y from a given set
of values of x and y. The formula is as follows
• xg = (x0)(L0) + (x1)(L1) + (x2)(L2) +…………+(xn-1)(Ln-1)
• L0 = (yg − y1) (yg − y2)……. (yg − yn-1)/ (y0 − y1 ) (y0 − y2 ) ……. (y0 − yn-1 )
• L1 = (yg − y0) (yg − y2)……. (yg − yn-1)/ (y1 − y0 ) (y1 − y2 ) ……. (y1 − yn-1 )
• L2 = (yg − y0) (yg − y1)……. (yg − yn-1)/ (y2 − y0 ) (y2 − y1 ) ……. (y2 − yn-1 )
• ……………………………………………………………………………………………….
• Ln-1 = (yg − y0) (yg − y1)……. (yg − yn-2)/ (yn-1 − y0 ) (yn-1 − y1 ) ……. (yn-1 − yn-2 )
Inverse Interpolation: Lagrange formula…cont
• Example: The following are co-ordinates of a set of points. Find x at
y=2 using Lagrange formula
x 0 1 2 3
y 0 1 7 25

• Solution: In this case we have, yg =2


• L0 = (yg − y1) (yg − y2) (yg − y3)/ (y0 − y1 ) (y0 − y2 ) (y0 − y3 )
=(2 − 1) (2 − 7) (2 − 25)/ (0 − 1 ) (0 − 7 ) (0 − 25 )
= - 0.6571
Inverse Interpolation: Lagrange formula…cont
• L1 = (yg − y0) (yg − y2) (yg − y3)/ (y1 − y0 ) (y1 − y2 ) (y1 − y3 )
=(2 − 0) (2 − 7) (2 − 25)/ (1 − 0 ) (1 − 7 ) (1 − 25 )
= 1.5972

• L2 = (yg − y0) (yg − y1) (yg − y3)/ (y2 − y0 ) (y2 − y1 ) (y2 − y3 )


=(2 − 0) (2 − 1) (2 − 25)/ (7 − 0 ) (7 − 1 ) (7 − 25 )
= 0.0608
The Lagrange Polynomial: Degree n Construction
• L3 = (yg − y0) (yg − y1) (yg − y2)/ (y3 − y0 ) (y3 − y1 ) (y3 − y2 )
=(2 − 0) (2 − 1) (2 − 7)/ (25 − 0 ) (25 − 1 ) (25 − 7 )
= - 9.2592 x 10-4

xg = (x0)(L0) + (x1)(L1) + (x2)(L2) + (x3)(L3)


= (0)(- 0.6571) + (1)(1.5972) + (2)(0.0608) + (3)(- 9.2592 x 10-4 )

xg = 1.7160 at yg = 2
Problems on Inverse Interpolation
1. The following table gives the values of x and y.

x 1.2 2.1 2.8 4.1


y 4.2 6.8 9.8 13.4

Find the value of x corresponding to y=12 using suitable method.


Problems on Inverse Interpolation
2. For the given table find the value of x for f(x)=0.390

x 20 25 30 35
f(x) 0.342 0.423 0.5 0.65
Problems on Inverse Interpolation
3. The following data gives the values of y corresponding to certain
values of x. Find the value of x when y=167.59789 by applying
Lagrange’s method.
x 1 2 5 7
y 1 12 117 317
Reference Books
1. Steven C. Chapra, Raymond P. Canale, Numerical Methods for
Engineers, 4/e, Tata McGraw Hill Editions
2. Dr. B. S. Garewal, Numerical Methods in Engineering and Science,
Khanna Publishers,.
3. Steven C. Chapra, Applied Numerical Methods with MATLAB for
Engineers and Scientist, Tata Mc-Graw Hill Publishing Co-Ltd
4. Rao V. Dukkipati, Applied Numerical Methods using Matlab, New
Age International Publishers
Reference Books …Contd
5. Gerald and Wheatley, Applied Numerical Analysis, Pearson
Education Asia
6. E. Balagurusamy, Numerical Methods, Tata McGraw Hill
7. P. Thangaraj, Computer Oriented Numerical Methods, PHI
8. S. S. Sastry, Introductory Methods of Numerical Analysis, PHI.
Lagrange Method of Interpolation

Compiled by
Dr. Shyam Arjun Sonawane
Associate Professor, Mechanical Engineering
Government College of Engineering & Research, Avasari (Kh)
What is Interpolation ?
• Given (x0,y0), (x1,y1), …… (xn,yn), find the value of ‘y’ at a value of ‘x’
that is not given.
Lagrange Interpolation
Lagrangian interpolating polynomial is given by
n
f n ( x) =  Li ( x) f ( xi )
i =0

where ‘ n ’ in f n (x) stands for the n th order polynomial that approximates the function y = f (x)

given at (n + 1) data points as (x0 , y 0 ), (x1 , y1 ),......, (x n −1 , y n −1 ), (x n , y n ) , and


n x − xj
Li ( x) = 
j =0 xi − x j
j i

Li (x) is a weighting function that includes a product of (n − 1) terms with terms of j = i


omitted.

3
The Lagrange Polynomial: The Linear Case
The problem of determining a polynomial of degree one that passes
through the distinct points
(x0, y0) and (x1, y1)
is the same as approximating a function f for which
f (x0) = y0 and f (x1) = y1
by means of a first-degree polynomial interpolating, or agreeing
with, the values of f at the given points.
Using this polynomial for approximation within the interval given by
the endpoints is called polynomial interpolation.
The Lagrange Polynomial: The Linear Case …cont
• Define the functions L0(x) = (x − x1)/ (x0 − x1 )and L1(x) = (x − x0) /(x1 −
x0) .

• The linear Lagrange interpolating polynomial though (x0, y0) and (x1,
y1) is

• P(x) = L0(x)f(x0) + L1(x)f(x1)


=((x − x1)/ (x0 − x1)) f(x0) + ((x − x0)/ (x1 − x0)) f(x1)
The Lagrange Polynomial: The Linear Case …cont
• Note that L0(x0) = 1, L0(x1) = 0, L1(x0) = 0, and L1(x1) = 1,
• which implies that
P(x0) = 1 · f(x0) + 0 · f(x1) = f(x0) = y0
and
P(x1) = 0 · f(x0) + 1 · f(x1) = f(x1) = y1.
• So P is the unique polynomial of degree at most 1 that passes
through (x0, y0) and (x1, y1).
The Lagrange Polynomial: The Linear Case …cont
• Example: Linear Interpolation
• Determine the linear Lagrange interpolating polynomial that passes
through the points (2, 4) and (5, 1).
• Solution: In this case we have
L0(x) = (x − 5)/(2 − 5) = − (1/3) (x − 5) and
L1(x) = (x − 2)/ (5 − 2) = (1/3) (x − 2),
• so
P(x) = − (1/3) (x − 5) * 4 + (1/3) (x − 2) *1
= -(4/3)x+(20/3)+(1/3)x-(2/3)
P(x) = −x + 6.
The Lagrange Polynomial: The Linear Case …cont

• The linear Lagrange interpolating polynomial that passes through the


points (2, 4) and (5, 1).
The Lagrange Polynomial: Degree n Construction
• To generalize the concept of linear interpolation, consider the
construction of a polynomial of degree at most n that passes
through the n + 1 points
(x0, f (x0)), (x1, f (x1)), . . . , (xn, f (xn)).

• Constructing the Degree n Polynomial


We first construct, for each k = 0, 1, . . . , n, a function Ln,k (x) with
the property that Ln,k (xi ) = 0 when i ≠ k and Ln,k (xk ) = 1.
The Lagrange Polynomial: Degree n Construction
…cont
• To satisfy Ln,k (xi ) = 0 for each i ≠ k requires that the numerator of
Ln,k (x) contain the term
(x − x0)(x − x1) · · · (x − xk−1)(x − xk+1) · · · (x − xn).
• To satisfy Ln,k (xk ) = 1, the denominator of Ln,k (x) must be this same
term but evaluated at x = xk .
• Thus
Ln,k (x) = [(x − x0) · · · (x − xk−1)(x − xk+1) · · · (x − xn)] /
[(xk − x0) · · · (xk − xk−1)(xk − xk+1) · · · (xk − xn)].
The Lagrange Polynomial: Degree n Construction
…cont
The Lagrange Polynomial: Degree n Construction
…cont

• Example: f (x) = (1/x)


(a) Use the numbers (called nodes) x0 = 2, x1 = 2.75 and x2 = 4 to find
the second Lagrange interpolating polynomial for f (x) = 1/x .
(b) Use this polynomial to approximate f (3) = 1/3
The Lagrange Polynomial: Degree n Construction
…cont
• Part (a): Solution
• We first determine the coefficient polynomials L0(x), L1(x), and
L2(x):
• L0(x) = [(x − 2.75)(x − 4)] / [(2 − 2.5)(2 − 4)]
= (2/3)[(x − 2.75)(x − 4)]
• L1(x) =[(x − 2)(x − 4)] / [(2.75 − 2)(2.75 − 4)]
= −(16/15)[(x − 2)(x − 4)]
• L2(x) =[(x − 2)(x − 2.75)] / [(4 − 2)(4 − 2.5)]
= (2/5)[(x − 2)(x − 2.75)]
The Lagrange Polynomial: Degree n Construction
…cont
The Lagrange Polynomial: Degree n Construction
…cont
(b) Use this polynomial to approximate f (3) = 1/3
Part (b): Solution
• An approximation to f (3) = 1/3 is
• f (3) ≈ P(3) = (9/22) − (105/88) + (49/44)
=(29/88)
≈ 0.32955.
The Lagrange Polynomial: Degree n Construction
…cont
Problems on Lagrange’s Interpolation
1. The velocity distribution of a fluid near a flat surface is given
below
x 0.1 0.3 0.6 0.8
V 0.72 1.81 2.73 3.47

Where x is the distance from the surface (mm) and V is the velocity
(mm/sec). Use Lagrange’s interpolation polynomial
Problems on Lagrange’s Interpolation
2. Using the following points, fit a polynomial using Lagrange’s
method and find the value of y at x=2.7

x 2.10 2.5 3.10 3.50


y 5.14 6.78 10.29 13.58
Problems on Lagrange’s Interpolation
3. Find the polynomial f(x) by using Lagrange’s interpolation formula
and hence fit f(3) for the following series

x 0 1 2 5
y 2 3 12 147
Problems on Lagrange’s Interpolation
4. Using Lagrange’s formula, find a unique polynomial P(x) of degree
2 or less and hence evaluate P(1.5)

x 1 3 4
y 1 27 54
Problems on Lagrange’s Interpolation
5. Using suitable interpolation formula find a polynomial which
passes the points

x 0 1 3 4
y -12 0 6 12
Problems on Lagrange’s Interpolation
6. Use Lagrange’s method to fit a polynomial to the following points
and find the value of y at x=1

x -1 0 2 3
y -8 3 1 12
Reference Books
1. Steven C. Chapra, Raymond P. Canale, Numerical Methods for
Engineers, 4/e, Tata McGraw Hill Editions
2. Dr. B. S. Garewal, Numerical Methods in Engineering and Science,
Khanna Publishers,.
3. Steven C. Chapra, Applied Numerical Methods with MATLAB for
Engineers and Scientist, Tata Mc-Graw Hill Publishing Co-Ltd
4. Rao V. Dukkipati, Applied Numerical Methods using Matlab, New
Age International Publishers
Reference Books …Contd
5. Gerald and Wheatley, Applied Numerical Analysis, Pearson
Education Asia
6. E. Balagurusamy, Numerical Methods, Tata McGraw Hill
7. P. Thangaraj, Computer Oriented Numerical Methods, PHI
8. S. S. Sastry, Introductory Methods of Numerical Analysis, PHI.
Newton’s Forward and Backward
Difference Interpolation

Compiled by
Dr. Shyam Arjun Sonawane
Associate Professor, Mechanical Engineering
Government College of Engineering & Research, Avasari (Kh)
What is Interpolation ?
• Given (x0,y0), (x1,y1), …… (xn,yn), find the value of ‘y’ at a value of ‘x’
that is not given.
Lagrange Interpolation Disadvantages
• The amount of computation required is large
• Interpolation for additional values of requires the same
amount of effort as the first value (i.e. no part of the previous
calculation can be used)
• When the number of interpolation points are changed
(increased/decreased), the results of the previous
computations can not be used
• Error estimation is difficult (at least may not be convenient)

3
Newton’s Forward Interpolation
• Use Newton Interpolation which is based on developing difference
tables for a given set of data points
• The Nth degree interpolating polynomial obtained by fitting N + 1
data points will be identical to that obtained using Lagrange
formulae!
• Newton interpolation is simply another technique for obtaining the
same interpolating polynomial as was obtained using the Lagrange
formulae
Newton’s Forward Interpolation …cont
• We assume equi-spaced points
Newton’s Forward Interpolation …cont
• Forward differences are now defined as follows:

• ∆0fi = fi (Zeroth order forward difference)


• ∆fi = fi + 1 - fi (First order forward difference)
• ∆2fi = ∆ fi + 1 - ∆ fi (Second order forward difference)
∆2fi = (fi + 2 – fi + 1 ) – (fi + 1 - fi )
∆2fi = fi + 2 – 2fi + 1 + fi
Newton’s Forward Interpolation …cont
• ∆3fi = ∆2 fi + 1 - ∆2 fi (Third order forward difference)
∆3fi = (fi + 3 – 2fi + 2 + fi + 1 ) – (fi + 2 – 2fi + 1 + fi )
∆3fi = fi + 3 –3fi + 2 + 3fi + 1 + fi

• ∆kfi = ∆k - 1 fi + 1 - ∆ k - 1 fi (kth order forward difference)


Newton’s Forward Interpolation …cont
• Typically we set up a difference table
Newton’s Forward Interpolation …cont
• Note that to compute higher order differences in the tables, we
take forward differences of previous order differences instead of
using expanded formulae.
• The order of the differences that can be computed depends on
how many total data points, x0…………xN , are available
• N + 1 data points can develop up to Nth order forward differences
Newton’s Forward Interpolation …cont
• Then put the values in the formula
• fg = f0 + u ∆fo + ((u(u-1)) / 2 !) ∆2fo + ((u(u-1) (u-2)) / 3 !) ∆3fo +
((u(u-1) (u-2) (u-3)) / 4 !) ∆4fo ……………………

Where u= ((xg – x0 ) / h)
h = step size
Newton’s Forward Interpolation …cont
Example: From the following table of yearly premium for policies
maturity at coming ages, estimate the premiums for policies
maturity at the age of 46 years.

Age (x) 45 50 55 60 65
Premium (y) 2.871 2.404 2.083 1.862 1.712
Newton’s Forward Interpolation …cont
Solution: (1) Calculate the value of h and u
h= x1 – x0
= 55 – 45
=5
u= ((xg – x0 ) / h)
= ((46 - 45) / 5 )
= 0.2
Newton’s Forward Interpolation …cont
(2) Prepare the Newton’s Forward difference table
x y ∆yo ∆2yo ∆3yo ∆4yo
45 2.871 -0.467 0.146 -0.046 0.017
50 2.404 -0.321 0.1 -0.029
55 2.083 -0.221 0.071
60 1.862 -0.15
65 1.712
Newton’s Forward Interpolation …cont
(3) Calculate the value of yg at xg = 46
yg = y0 + u ∆yo + ((u(u-1)) / 2 !) ∆2yo + ((u(u-1) (u-2)) / 3 !) ∆3yo +
((u(u-1) (u-2) (u-3)) / 4 !) ∆4yo

yg = 2.871 + (0.2)(-0.467) + ((0.2(0.2 -1)) / 2 !) (0.146) + ((0.2(0.2 -1)


(0.2 -2)) / 3 !) (-0.046) + ((0.2(0.2 -1) (0.2 -2) (0.2 -3)) / 4 !) (0.017)
Newton’s Forward Interpolation …cont
• yg = 2.871 – 0.0934 – 0.01168 – 2.208 x10-3 – 5.712 x 10-4

• yg = 2.7631

• At xg = 46 , yg = 2.7631 (Answer)
Problems on Newton’s Forward Interpolation
1. State the order of polynomial which might be suitable for
following function. Calculate f(3.5) using forward difference
formula

x 2 3 4 5 6 7 8 9
y 19 48 99 178 291 444 643 894
Problems on Newton’s Forward Interpolation
2. Find the value of y for x=0.5 for the following table of x, y values
using Newton’s forward difference formula

x 0 1 2 3 4
y 1 5 25 100 250
Problems on Newton’s Forward Interpolation
3. From the tabulated values of x and y given below prepare forward
difference table. Find the polynomial passing through the points and
estimate the value of y when x=1.5. Also find the slope of curve at
x=1.5

x 0 2 4 6 8
y 5 29 125 341 725
Problems on Newton’s Forward Interpolation
4. Find the polynomial passing through the following points using
Newton’s forward difference formula and hence find y and dy/dx at x
=0.5

x 0 1 2 3 4 5
y 1 1 7 25 61 12
Problems on Newton’s Forward Interpolation
5. Following is the table of square roots. Calculate the values of
square root of 151 and 155 by using Newton’s forward difference
formula
x 0 1 3 4
y -12 0 6 12
Problems on Newton’s Forward Interpolation
6. The following data are taken from the steam table. Find the
pressure at t=142⁰C using Newton’s forward difference formula

T (⁰C) 140 150 160 170 180


P (Kgf/cm2) 3.685 4.854 6.302 8.076 10.225
Problems on Newton’s Forward Interpolation
7. The velocity distribution of a fluid near a flat surface is given below.
Where x is the distance from the surface (cm) and V is the velocity
(cm/sec). Using Newton’s forward interpolation formula obtain the
velocity at x=0.4, 0.4, 0.6 & 0.8

x 0.1 0.3 0.5 0.7 0.9


V 0.72 1.81 2.73 3.47 3.98
Newton’s Backward Interpolation
• Newton backward interpolation is essentially the same as Newton
forward interpolation except that backward differences are used
Newton’s Backward Interpolation …cont
Newton’s Backward Interpolation …cont
• Typically we set up a difference table
x y

x0 y0

x1 y1

x2 y2

x3 y3
Newton’s Backward Interpolation …cont
Newton’s Backward Interpolation …cont
Example: For the following data using backward difference
polynomial interpolate at x = 0.25

x 0.1 0.2 0.3 0.4 0.5


y 1.4 1.56 1.76 2.00 2.28
Newton’s Backward Interpolation …cont
Solution: (1) Calculate the value of h and u
h= x1 – x0
= 0.2 – 0.1
= 0.1
u= ((xn - 1 – xg ) / h)
= ((0.5 – 0.25) / 0.1 )
= 1.5
Newton’s Backward Interpolation …cont
(2) Prepare the Newton’s backward difference table
x y

0.1 1.4

0.2 1.56 0.16

0.3 1.76 0.2 0.04

0.4 2.0 0.24 0.04 0

0.5 2.28 0.28 0.04 0 0

---- yn - 1
Newton’s Backward Interpolation …cont
Problem on Newton’s Backward Interpolation
1. Prepare the backward difference table for the given values of x and
y

x 0 2 4 6 8 10
y 2 6 8 9 11 15
Reference Books
1. Steven C. Chapra, Raymond P. Canale, Numerical Methods for
Engineers, 4/e, Tata McGraw Hill Editions
2. Dr. B. S. Garewal, Numerical Methods in Engineering and Science,
Khanna Publishers,.
3. Steven C. Chapra, Applied Numerical Methods with MATLAB for
Engineers and Scientist, Tata Mc-Graw Hill Publishing Co-Ltd
4. Rao V. Dukkipati, Applied Numerical Methods using Matlab, New
Age International Publishers
Reference Books …Contd
5. Gerald and Wheatley, Applied Numerical Analysis, Pearson
Education Asia
6. E. Balagurusamy, Numerical Methods, Tata McGraw Hill
7. P. Thangaraj, Computer Oriented Numerical Methods, PHI
8. S. S. Sastry, Introductory Methods of Numerical Analysis, PHI.

You might also like