Download presentation
Presentation is loading. Please wait.
Published byMargery Anthony Modified over 9 years ago
1
Numerical Methods For Slides Thanks to Lecture 6 Interpolation
Direct Method & Lagrange Method For Slides Thanks to Dr. S. M. Lutful Kabir Visiting Professor, BRAC University & Professor, BUET
2
What is interpolation? Many times, data is given only at discrete points such as So, how then does one find the value of y at any other value of x ? Well, a continuous function f(x) may be used to represent the n+1 data values with f(x) passing through the n+1 points (Figure 1). Then one can find the value of y at any other value of x. This is called interpolation. y (x3,y3) (x1,y1) Figure 1 (x2,y2) f(x) (x0,y0) x
3
Polynomial interpolation?
Of course, if new ‘x’ falls outside the range of x for which the data is given, it is no longer interpolation but instead is called extrapolation. So what kind of function f(x) should one choose? A polynomial is a common choice for an interpolating function because polynomials are easy to evaluate, differentiate, and integrate relative to other choices such as a trigonometric and exponential series Polynomial interpolation involves finding a polynomial of order n that passes through the n+1 points
4
Direct Method of Interpolation
One of the methods of interpolation is called the direct method. Other methods include the Lagrangian interpolation method and Newton’s divided difference polynomial method The direct method of interpolation is based on the following premise. Given n+1 data points, fit a polynomial of order n as given below (1) through the data, where a0, a1, a2, an+1, an are real constants.
5
Direct Method of Interpolation (continued)
Since values of f(x) are given at values of x, one can write equations
6
Direct Method of Interpolation (continued)
Then the constants, can be found by solving the simultaneous linear equations. To find the value of f(x) at a given value of x, simply substitute the value of x in Equation 1. But, it is not necessary to use all the data points. How does one then choose the order of the polynomial and what data points to use? This concept and the direct method of interpolation are best illustrated using examples
7
Example 1 The upward velocity of a rocket is given as a function of time in Table 1. Corresponding graph is shown in Figure 1 Table 1: Velocity as function of time Figure 1: Graph of Velocity Time (s) Velocity (m/s) 10 227.04 15 362.78 20 517.35 22.5 602.97 30 901.67 Determine the value of the velocity at t = 16seconds using the direct method of interpolation and a first order polynomial.
8
Solution to example 1 For first order polynomial interpolation (also called linear interpolation), the velocity is given by y (x1 , y1) f1(x) (x0 , y0) x Figure 3 Linear interpolation
9
Solution to example 1 (continued)
Since we want to find the velocity at t=16 sec, and we are using a first order polynomial, we need to choose the two data points that are closest to t = 16 sec that also bracket t=16 sec to evaluate it. The two points are t0=15 sec and t1=20 sec Then t0=15, v(t0)= a0= t1=20, v(t1)= a1=30.914 Gives v(15)=a0+a1 x 15= v(t)=ao+a1t v(20)=a0+a1 x 20= v(16)=393.7
10
Example 2 Determine the value of the velocity at t = 16 seconds using the direct method of interpolation and a second order polynomial. Solution For second order polynomial interpolation (also called quadratic interpolation), the velocity is given by v(t)=a0+a1t+a2t2 y x1 , y1 x2 , y2 f(x) x0 , y0 x
11
Solution to example 2 (continued)
Since we want to find the velocity at t=16, and we are using a second order polynomial, we need to choose the three data points that are closest to t = 16 that also bracket t = 16 to evaluate it. The three points are t0=10, t1=15 and t2=20 Then v(10)=227.04=a0+a1 x 10+a2 x 102 v(15)=362.78=a0+a1 x 15+a2 x 152 v(20)=517.35=a0+a1 x 20+a2 x 202 They gives, a0=12.05 a1=17.733 a2=0.3766
12
Solution to example 2 (continued)
Hence v(t)= t t2 V(16)= m/s The absolute relative approximate error obtained between the results from the first and second order polynomial is
13
Example 3 For the rocket problem of the previous examples
a) Determine the value of the velocity at t=16 seconds using the direct method of interpolation and a third order polynomial. b) Find the absolute relative approximate error for the third order polynomial approximation. c) Using the third order polynomial interpolant for velocity from part (a), find the distance covered by the rocket from t=11 s to t=16 s. d) Using the third order polynomial interpolant for velocity from part (a), find the acceleration of the rocket at t=16s.
14
Solution to example 3 For third order polynomial interpolation (also called cubic interpolation), we choose the velocity given by y (x3 , y3) (x1 , y1) (x2 , y2) f3(x) (x0 , y0) x
15
Solution to example 3 (continued)
Since we want to find the velocity at t=16, and we are using a third order polynomial, we need to choose the four data points closest to and also bracket that. The four points are (t0, v0)=(10, ), (t1, v1)=(15, ), (t2, v2)=(20, ) and (t3, v3)=(22.5, ) Solving the above four equations gives a0= a1= a2= a3= Hence, v(t) = t t t3 So, v(16)= m/s
16
Solution to example 3 (continued)
b) The absolute percentage relative approximate error for the value obtained for v(16) between second and third order polynomial is c) The distance covered by the rocket between t=11s and t=16s can be calculated from the interpolating polynomial Note that the polynomial is valid between t = 10 s and t = 22.5 s and hence includes the limits of integration of t = 11 s and t = 16 s
17
Solution to example 3 (continued)
= = 1605m d) The acceleration at t=16sec is given by, So, a(16) = m/s2
18
Solving the coefficients of polynomial having high order
If the polynomial is of nth order, there are n numbers of unknowns, how to find out them? One way is to arrange the equations in matrix form as shown below: [Y] = [C] [A] Since [Y] = [C] [A] So, [A] = [C]-1 [Y]
19
Langrange Method The Lagrangian interpolating polynomial is given by
where n in fn(x) stands for the nth order polynomial that approximates the function y=f(x) given at n+1 data points as (x0,y0), (x1,y1), (x2,y2),……. (xn-1,yn-1), (xn, yn) and Li(x) is a weighting function that includes a product of n-1 terms with terms of j = i omitted. The application of Lagrangian interpolation will be clarified using an example.
20
Example 4 Determine the value of the velocity of the rocket problem at t=16 seconds using a first order Lagrange polynomial. Solution For first order polynomial interpolation (also called linear interpolation), the velocity is given by Hence, v(16) = m/s
21
Since we want to find the velocity at
Solution to example 4 to evaluate it. The three points are . For quadratic approximation, Since we want to find the velocity at t=16 , and we are using a second order polynomial, we need to choose the three data points that are closest to t=16 that also bracket t=16 to evaluate it. The three points are t0=10, t1=15 and t2=20, hence, v(16)= m/s b) The absolute relative approximate error with respect to direct method is
22
Flow Chart for Direct Method
1 Start 9 F 5 for i=1..n+1 for i=1..n+1 2 n F T T x(i), y(i), i=1,1,....n+1 10 a(i)=0 6 3 for j=1..n+1 F 11 F T for j=1..n+1 4 7 xu 12 T c(i,j)=x(i)^(j-1) a(i)=a(i)+ci(i,j)*y(j) ci=inv(c) 8 fxu=0 13 F 14 for i=1..n+1 T 17 16 15 fxu=fxu+a(i)*xu^(i-1) End xu, fxu
23
Flow Chart for Langrage method
1 Start 7 2 n L(i)=1 9 x(i), y(i), i=1...n+1 T j : i 3 for j=1..n+1 = = F 8 4 xu L(i)=L(i)*(xu-x(j))/(x(i)-x(j)) 5 fxu=0 10 fxu=fxu+L(i)*y(i) 11 6 for i=1..n+1 T 12 F xu, fxu End 10
24
Thanks
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.