0% found this document useful (0 votes)
39 views14 pages

Chapter 2

Numerical Analysis

Uploaded by

haohiepdu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views14 pages

Chapter 2

Numerical Analysis

Uploaded by

haohiepdu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

CHAPTER 2: LANGRANGE INTERPOLATING FUNCTIONS &

INTERPOLATION

2.1 THEORY

2.1.1 Interpolation

In numerical analysis, interpolation is a method of estimating intermediate values


between precise data points. The most common method used for this purpose is
polynomial interpolation. Recall that the general formula for an nth-order polynomial is:
2 n
f ( x )=a0 +a 1 x +a2 x + …+an x

For n + 1 data points, there is one and only one polynomial of order n that passes through
all the points. For example, there is only one straight line (that is, a first-order
polynomial) that connects two points (Fig. 2.1a). Similarly, only one parabola connects a
set of three points (Fig. 2.1b). Polynomial interpolation consists of determining the
unique nth-order polynomial that fits n + 1 data points. This polynomial then provides a
formula to compute intermediate values.

FIGURE 2.1

Examples of interpolating polynomials: (a) first order (linear) connecting two points, (b) second- order
(quadratic or parabolic) connecting three points, and (c) third - order (cubic) connecting four points.
Although there is one and only one nth-order polynomial that fits n + 1 points, there are a
variety of mathematical formats in which this polynomial can be expressed. One well-
suited alternative for computer implementation is Lagrange polynomials.

2.1.2 Lagrange interpolating polynomials

Lagrange interpolating polynomials can be represented concisely as


n
f n ( x)=∑ ❑ Li ( x )f ( x i )
i=0

Where:
n
x−x j
Li ( x)=∏ ❑ (1)
j=0 xi −x j
j ≠1

where Π designates the “product of.” For example, the linear version (n = 1) is:

x −x1 x−x 0 (2)


f 1 ( x)= f ( x0)+ f ( x1 )
x 0−x 1 x 1−x 0

and the second-order version is:

( x−x 1 ) ( x−x 2 ) ( x−x 0 ) ( x−x 2 )


f 2 ( x)=¿ f ( x0 )+ f ( x1 )
( x 0−x 1 ) ( x 0−x 2 ) ( x 1−x 0 ) ( x 1−x 2 ) (3)
( x −x 0) ( x−x 1 )
¿+ f ( x 2)
( x2 −x 0) ( x 2−x 1 )

the rationale underlying the Lagrange formulation can be grasped directly by realizing
that each term Li ( x) will be 1 at x = x i and 0 at all other sample points. (Fig. 2.2)

N i = 1 at node i; N i = 0 at nodes j with j ≠ I (property 1)


FIGURE 2.2

A visual depiction of the rationale behind the Lagrange polynomial. This figure shows a second-order
case. Each of the three terms in Eq. (3) passes through one of the data points and is zero at the other two.
The summation of the three terms must, therefore, be the unique second order polynomial f 2 ( x) that
passes exactly through the three points.

Thus, each product Li f (x i ) takes on the value of f (x i) at the sample point x i .


Consequently, the summation of all the products designated by Eq. (1) is the unique nth-
order polynomial that passes exactly through all n + 1 data points.
n

∑ ❑ N i =1
i=1

2.1.3 Determine 3 interpolating Functions

This method is illustrated with the following example:


¿ N 1 (x , y )=
[ ( x 2 y 3−x 3 y 2 ) + x ( y 2− y 3 ) + y ( x 3−x 2 ) ]
2A
[ ( x 3 y 1−x 1 y 3 ) + x ( y 3− y 1 ) + y ( x 1−x 3 ) ]
¿ N 2 (x , y)=
2A

¿ N 3 (x , y)=
[ ( x 1 y 2−x 2 y 1 ) + x ( y 1− y 2 ) + y ( x 2−x 1 ) ]
2A

With A is the area of the triangle:

| |
¿ x ∧¿ y 1∧¿ 1
1 1 1
A = ¿ x 2∧¿ y 2∧¿ 1 = |x 1 ( y 2− y 3 )+ x 2 ( y 3 − y 1)+ x 3 ( y 1− y 2 )|
2 2
¿ x 3∧¿ y 3∧¿ 1

2.2 EXAMPLE

Example 1: Use a Lagrange interpolating polynomial of the (a)first and (b) the second
order to evaluate √ 2 on the basis of the data given in the table below:

x 1 3 6

f (x) 1 1.732050 2.449490


Solution:

(a) The first-order polynomial [Eq. (2)] can be used to obtain the estimate at x=2,

2−3 2−1
f 1 (2)= 1+ 1.732050=1.366025
1−3 3−1

(b) In a similar fashion, the second-order polynomial is developed as [Eq. (3)]

( 2−3 )( 2−6 ) ( 2−1 )( 2−6 )


f 2 ( x)=¿ 1+ 1.732050
( 1−3 )( 1−6 ) ( 3−1 )( 3−6 )
( 2−1 ) ( 2−3 )
¿+ 2.449490=1.391401
( 6−1 ) ( 6−3 )

Example 2:

Consider the following element (ABCD is a rectangular):

Given: TA (0,0) =100°, TB (0,2) =60°, TC (4,2) = 50°, TD (4,0) = 90°

Interpolate temperature at M (x= 2; y= 1), TM (2,1) = ?

Solution:

Firstly, we hold the y = 2 fixed and apply one-dimensional interpolation in the x-


dimension. Using the Lagrange first-order, we get:

x−x C x−x B
T (x , 2)= T B ( xB , 2)+ T ( x , 2)
x B−x C x C −x B C C

2−4 2−0 1 1
→ T (2 , 2)= T B (0 , 2) + T C ( 4 ,2 )= 60 °+ 50 °=55 °
0−4 4−0 2 2
Secondly, we hold the y = 0 fixed and apply one-dimensional interpolation in the x-
dimension. Using the Lagrange first-order, we get:

x−x D x−x A
T (x , 0)= T A ( x A , 0)+ T ( x , 0)
x A−x D x D −x A D D

2−4 2−0 1 1
→ T (2 , 0)= T ( 0 ,0 )+ T ( 4 , 0 )= 100 ° + 90 °=55 °
0−4 A 4−0 D 2 2

Finally, we hold the x = 2 fixed and apply one-dimensional interpolation in the y-


dimension. Using the Lagrange first-order, we get:

y M −0 y M −2 1−0 1−2
T M (2 , 1)= T ( 2 , 2 )+ T ( 2 ,0 )= 55° + 95 °=75 °
2−0 0−2 2−0 0−2

Example 3:

Consider a 3-node triangular element as shown in the following figure:

Three values of nodal temperature T1= 100°, T2= 60°, T3= 50° are given at node 1, node 2,
node 3, respectively.

Interpolate temperature at M (x= 3; y= 3), TM (3,3) =?

Solution:

A is the area of the triangle:

| |
¿ x 1∧¿ y 1∧¿ 1
1 1 1
A= ¿ x 2∧¿ y 2∧¿ 1 = | x1 ( y 2− y 3 ) + x 2 ( y 3− y 1 ) + x 3 ( y 1− y 2 )|¿ |1 ( 5−2 ) +3 ( 2−2 )+ 6 ( 2−5 )|=7.5
2 2 2
¿ x3 ∧¿ y 3∧¿ 1

interpolating functions are determined by:


¿ N 1 (1 , 2)=
[ ( x 2 y 3−x 3 y 2) + x ( y 2− y 3 ) + y ( x 3−x 2 ) ]
2A
[ ( x 3 y 1−x 1 y 3 ) + x ( y 3 − y 1 )+ y ( x 1−x 3 ) ]
¿ N 2 (3 , 5)=
2A

¿ N 3 (6 ,2)=
[ ( x 1 y 2−x 2 y 1 ) + x ( y 1− y 2 )+ y ( x 2−x 1 ) ]
2A
[ ( 3 ×2−6 ×5 ) + x ( 5−2 ) + y ( 6−3 ) ] 3 x +3 y−24
¿→ N 1 (1 , 2)= =
2 ×7.5 15
[ ( 6 ×2−1× 2 ) + x ( 2−2 )+ y ( 1−6 ) ] −5 y+ 10
¿ → N 2(3 ,5)= =
2 ×7.5 15
[ ( 1 ×5−3 ×2 ) + x ( 2−5 ) + y ( 3−1 ) ] −3 x+2 y−1
¿ → N 3 (6 , 2)= =
2× 7.5 15

Interpolate temperature at M (x= 3; y= 3) by:

T M ( 3 ,3 )=N 1 ( 1, 2 ) T 1 + N 2 ( 3 ,5 ) T 2+ N 3 ( 6 ,2 ) T 3
3× 3+3 ×3−24 −5 ×3+10 −3 ×3+ 2× 3−1
¿ 100° + 60 °+ 50 °=−73.3333°
15 15 15

2.3 SOFTWARE USING C PROGRAMMING LANGUAGE

Example 1: Use a Lagrange interpolating polynomial of the first and second order to
evaluate √ 2 on the basis of the data given in the table below:

x 1 3 6

f (x) 1 1.732050 2.449490

Solution:

#include <stdio.h>

void main (){

float x[100], y[100], xp, yp = 0, p;


int i, j, n;

printf("Number of data: ");

scanf("%d", &n);

printf("Enter data:\n");

for (i=1; i <= n; i++){

printf("x[%d] = ", i); scanf("%f", &x[i]);

printf("y[%d] = ", i); scanf("%f", &y[i]);

printf("Interpolation point: ");

scanf("%f", &xp);

for (i=1; i <= n; i++){

p=1;

for (j=1; j <= n; j++){

if (i !=j ) {

p = p*(xp-x[j])/(x[i] -x[j]);

yp = yp + p*y[i];}
printf("Value of the interpolation point %f: %f",xp, yp);

Result:

(a)

(b)

Example 2:

Consider the following element (ABCD is a rectangular):

Given: TA (0,0) = 100°, TB (0,2) =60°, TC(4,2) = 50°, TD(4,0) = 90°


Interpolate temperature at M (x= 2; y= 1), TM (2,1) = ?

Solution:

#include <stdio.h>

void main (){

float x[100], y[100],T[100], xp, yp, T1, T2, Tp ;

int i, j, n = 4;

printf("Enter data:\n");

for (i=1; i <= n; i++){

printf("x[%d] = ", i); scanf("%f", &x[i]);

printf("y[%d] = ", i); scanf("%f", &y[i]);

printf("T[%d] = ", i); scanf("%f", &T[i]);

printf("Interpolation point: ");

scanf("%f %f",&xp, &yp);

T1 = ((xp - x[4])/(x[1]-x[4]))*T[1] + ((xp - x[1])/(x[4]-x[1]))*T[4];

T2 = ((xp - x[3])/(x[2]-x[3]))*T[2] + ((xp - x[2])/(x[3]-x[2]))*T[3];

Tp = ((yp - y[2])/(y[1]-y[2]))*T1 + ((yp - y[1])/(y[2]-y[1]))*T2;


printf("Value of the interpolation point (%f;%f): %f",xp, yp, Tp);

Result:

Example 3:

Consider a 3-node triangular element as shown in the following figure:

Three values of nodal temperature T1= 100°, T2= 60°, T3= 50° are given at node 1, node 2,
node 3; respectively.

Interpolate temperature at M (x= 3; y= 3), TM (3,3) =?

Solution:

#include <stdio.h>
void main (){

float x[100], y[100],T[100];

float xp, yp, N1, N2, N3, Tp, A, a;

int i, j, n = 3;

printf("Enter data:\n");

for (i=1; i <= n; i++){

printf("x[%d] = ", i); scanf("%f", &x[i]);

printf("y[%d] = ", i); scanf("%f", &y[i]);

printf("T[%d] = ", i); scanf("%f", &T[i]);

printf("Interpolation point: ");

scanf("%f %f",&xp, &yp);

a = 0.5*(x[1]*(y[2]-y[3])+x[2]*(y[3]-y[1])+x[3]*(y[1]-y[2]));

if (a < 0)

A = -1*a;

else

A = a;

N1 = ((x[2]*y[3]-x[3]*y[2]) + xp*(y[2]-y[3]) + yp*(x[3]-x[2]))/(2*A);

N2 = ((x[3]*y[1]-x[1]*y[3]) + xp*(y[3]-y[1]) + yp*(x[1]-x[3]))/(2*A);


N3 = ((x[1]*y[2]-x[2]*y[1]) + xp*(y[1]-y[2]) + yp*(x[2]-x[1]))/(2*A);

Tp = N1*T[1] + N2*T[2] + N3*T[3];

printf("Value of the interpolation point (%f;%f): %.4f",xp, yp, Tp);

Result:

2.4 ERROR

The accuracy of the result is affected by the order of the Lagrange function we use to
approximate. The result is more precise when the order is higher. But we must consider
the demand and the situation when we pick the order. For instance, if we only have 2
points of a function, a linear polynomial is appropriate.

2.5 CONCLUSION

The results obtained through manual calculations and software-based solutions are
identical. The choice of method depends on the specific circumstances. Using
Polynomials for interpolating is simple, they are enough for our applications. For
instance, Interpolating functions use for interpolating physical quantities such as
temperature, stress, etc. However, this method has its limitations, for instance, if a new
data point is measured, the interpolation functions need to be recalculated.

You might also like