Chapter 2
Chapter 2
INTERPOLATION
2.1 THEORY
2.1.1 Interpolation
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.
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:
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)
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.
∑ ❑ N i =1
i=1
¿ N 3 (x , y)=
[ ( x 1 y 2−x 2 y 1 ) + x ( y 1− y 2 ) + y ( x 2−x 1 ) ]
2A
| |
¿ 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
(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
Example 2:
Solution:
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
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:
Three values of nodal temperature T1= 100°, T2= 60°, T3= 50° are given at node 1, node 2,
node 3, respectively.
Solution:
| |
¿ 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
¿ 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
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
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
Solution:
#include <stdio.h>
scanf("%d", &n);
printf("Enter data:\n");
scanf("%f", &xp);
p=1;
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:
Solution:
#include <stdio.h>
int i, j, n = 4;
printf("Enter data:\n");
Result:
Example 3:
Three values of nodal temperature T1= 100°, T2= 60°, T3= 50° are given at node 1, node 2,
node 3; respectively.
Solution:
#include <stdio.h>
void main (){
int i, j, n = 3;
printf("Enter data:\n");
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;
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.