0% found this document useful (0 votes)
40 views7 pages

Practical 5 - Lagrange Interpolation

Uploaded by

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

Practical 5 - Lagrange Interpolation

Uploaded by

achalasingh49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LAGRANGE INTERPOLATION

QUESTION 1 :

X = {1, 2, 3};
Y = {2, 5, 10};
n = 3;
For[i = 1, i ≤ n, i ++,
Ln, i, x_ = Productx - Xj  Xi - Xj, j, 1, i - 1 *

Productx - Xj  Xi - Xj, j, i + 1, n


Lagrange[x_] = SumYi * L[n, i, x], i, 1, n
Simplify[Lagrange[x]];
Print" Langrange Polynomial: ", Lagrange[x]
Print "Simplified Lagrange Polynomial: ", Simplify[Lagrange[x]]
Lagrange [1]

Out[5]= (2 - x) (3 - x) + 5 (3 - x) (- 1 + x) + 5 (- 2 + x) (- 1 + x)

Langrange Polynomial: (2 - x) (3 - x) + 5 (3 - x) (- 1 + x) + 5 (- 2 + x) (- 1 + x)
Simplified Lagrange Polynomial: 1 + x2
Out[9]= 2
2

QUESTION 2 :

X = {- 2, - 1, 0, 1, 3, 4};
Y = {9, 16, 17, 18, 44, 81};
n = 6;
For[i = 1, i ≤ n, i ++,
Ln, i, x_ = Productx - Xj  Xi - Xj, j, 1, i - 1 *

Productx - Xj  Xi - Xj, j, i + 1, n


Lagrange[x_] = SumYi * L[n, i, x], i, 1, n
Simplify[Lagrange[x]];
Print" Langrange Polynomial: ", Lagrange[x]
Print "Simplified Lagrange Polynomial: ", Simplify[Lagrange[x]]
Lagrange [0.5]
Lagrange[3.1]

Out[14]=
1 2 17
- (- 1 - x) (1 - x) (3 - x) (4 - x) x - (1 - x) (3 - x) (4 - x) x (2 + x) + (1 - x) (3 - x) (4 - x) (1 + x) (2 + x) +
20 5 24
1 11 9
(3 - x) (4 - x) x (1 + x) (2 + x) + (4 - x) (- 1 + x) x (1 + x) (2 + x) + (- 3 + x) (- 1 + x) x (1 + x) (2 + x)
2 30 40

Langrange Polynomial:
1 2 17
- (- 1 - x) (1 - x) (3 - x) (4 - x) x - (1 - x) (3 - x) (4 - x) x (2 + x) + (1 - x) (3 - x) (4 - x) (1 + x) (2 + x) +
20 5 24
1 11 9
(3 - x) (4 - x) x (1 + x) (2 + x) + (4 - x) (- 1 + x) x (1 + x) (2 + x) + (- 3 + x) (- 1 + x) x (1 + x) (2 + x)
2 30 40
Simplified Lagrange Polynomial: 17 + x3
Out[18]=
17.125
Out[19]=
46.791
3

QUESTION 3 :

X = {1, 3, 4, 5, 7, 10};
Y = {3, 31, 69, 131, 351, 1011};
n = 6;
For[i = 1, i ≤ n, i ++,
Ln, i, x_ = Productx - Xj  Xi - Xj, j, 1, i - 1 *

Productx - Xj  Xi - Xj, j, i + 1, n


Lagrange[x_] = SumYi * L[n, i, x], i, 1, n
Simplify[Lagrange[x]];
Print" Langrange Polynomial: ", Lagrange[x]
Print "Simplified Lagrange Polynomial: ", Simplify[Lagrange[x]]
Lagrange [3.5]
Lagrange[8]

Out[24]=
1 31
(3 - x) (4 - x) (5 - x) (7 - x) (10 - x) +
(4 - x) (5 - x) (7 - x) (10 - x) (- 1 + x) +
432 112
23 131
(5 - x) (7 - x) (10 - x) (- 3 + x) (- 1 + x) + (7 - x) (10 - x) (- 4 + x) (- 3 + x) (- 1 + x) +
18 80
13 337 (- 7 + x) (- 5 + x) (- 4 + x) (- 3 + x) (- 1 + x)
(10 - x) (- 5 + x) (- 4 + x) (- 3 + x) (- 1 + x) +
16 1890
1 31
Langrange Polynomial: (3 - x) (4 - x) (5 - x) (7 - x) (10 - x) + (4 - x) (5 - x) (7 - x) (10 - x) (- 1 + x) +
432 112
23 131
(5 - x) (7 - x) (10 - x) (- 3 + x) (- 1 + x) + (7 - x) (10 - x) (- 4 + x) (- 3 + x) (- 1 + x) +
18 80
13 337 (- 7 + x) (- 5 + x) (- 4 + x) (- 3 + x) (- 1 + x)
(10 - x) (- 5 + x) (- 4 + x) (- 3 + x) (- 1 + x) +
16 1890
Simplified Lagrange Polynomial: 1 + x + x3
Out[28]=
47.375
Out[29]=
521
4

QUESTION 4 :

X = {0, 1, 2, 4, 5, 6};
Y = {1, 14, 15, 5, 6, 19};
n = 6;
For[i = 1, i ≤ n, i ++,
Ln, i, x_ = Productx - Xj  Xi - Xj, j, 1, i - 1 *

Productx - Xj  Xi - Xj, j, i + 1, n


Lagrange[x_] = SumYi * L[n, i, x], i, 1, n
Simplify[Lagrange[x]];
Print" Langrange Polynomial: ", Lagrange[x]
Print "Simplified Lagrange Polynomial: ", Simplify[Lagrange[x]]
Lagrange [3]
Lagrange[5.5]

Out[34]=
1 7 5
(1 - x) (2 - x) (4 - x) (5 - x) (6 - x) + (2 - x) (4 - x) (5 - x) (6 - x) x + (4 - x) (5 - x) (6 - x) (- 1 + x) x +
240 30 16
5 1 19
(5 - x) (6 - x) (- 2 + x) (- 1 + x) x + (6 - x) (- 4 + x) (- 2 + x) (- 1 + x) x + (- 5 + x) (- 4 + x) (- 2 + x) (- 1 + x) x
48 10 240

Langrange Polynomial:
1 7 5
(1 - x) (2 - x) (4 - x) (5 - x) (6 - x) + (2 - x) (4 - x) (5 - x) (6 - x) x + (4 - x) (5 - x) (6 - x) (- 1 + x) x +
240 30 16
5 1 19
(5 - x) (6 - x) (- 2 + x) (- 1 + x) x + (6 - x) (- 4 + x) (- 2 + x) (- 1 + x) x + (- 5 + x) (- 4 + x) (- 2 + x) (- 1 + x) x
48 10 240
Simplified Lagrange Polynomial: 1 + 21 x - 9 x2 + x3
Out[38]=
10
Out[39]=
10.625
5

QUESTION 5 :

X = {- 1, 1, 4, 7};
Y = {- 2, 0, 63, 342};
n = 4;
For[i = 1, i ≤ n, i ++,
Ln, i, x_ = Productx - Xj  Xi - Xj, j, 1, i - 1 *

Productx - Xj  Xi - Xj, j, i + 1, n


Lagrange[x_] = SumYi * L[n, i, x], i, 1, n
Simplify[Lagrange[x]];
Print" Langrange Polynomial: ", Lagrange[x]
Print "Simplified Lagrange Polynomial: ", Simplify[Lagrange[x]]
Lagrange [3.1]
Lagrange[0.5]

Out[44]=
1 7 19
- (1 - x) (4 - x) (7 - x) + (7 - x) (- 1 + x) (1 + x) + (- 4 + x) (- 1 + x) (1 + x)
40 5 8
1 7 19
Langrange Polynomial: - (1 - x) (4 - x) (7 - x) + (7 - x) (- 1 + x) (1 + x) + (- 4 + x) (- 1 + x) (1 + x)
40 5 8
Simplified Lagrange Polynomial: -1 + x3
Out[48]=
28.791
Out[49]=
- 0.875
6

QUESTION 6 :

X = {- 1, 2, 4, 5};
Y = {- 5, 13, 255, 625};
n = 4;
For[i = 1, i ≤ n, i ++,
Ln, i, x_ = Productx - Xj  Xi - Xj, j, 1, i - 1 *

Productx - Xj  Xi - Xj, j, i + 1, n


Lagrange[x_] = SumYi * L[n, i, x], i, 1, n
Simplify[Lagrange[x]];
Print" Langrange Polynomial: ", Lagrange[x]
Print "Simplified Lagrange Polynomial: ", Simplify[Lagrange[x]]
Lagrange [3]

Out[146]=
1 13 51 625
- (2 - x) (4 - x) (5 - x) + (4 - x) (5 - x) (1 + x) + (5 - x) (- 2 + x) (1 + x) + (- 4 + x) (- 2 + x) (1 + x)
18 18 2 18

Langrange Polynomial:
1 13 51 625
- (2 - x) (4 - x) (5 - x) + (4 - x) (5 - x) (1 + x) + (5 - x) (- 2 + x) (1 + x) + (- 4 + x) (- 2 + x) (1 + x)
18 18 2 18
Simplified Lagrange Polynomial: 35 + 3 x - 27 x2 + 10 x3
Out[150]=

71

QUESTION 7 :

X = 10 Degree, 20 Degree, 30 Degree;


Y = {1.1585, 1.2817, 1.3660};
n = 3;
For[i = 1, i ≤ n, i ++,
Ln, i, x_ = Productx - Xj  Xi - Xj, j, 1, i - 1 *

Productx - Xj  Xi - Xj, j, i + 1, n


Lagrange[x_] = SumYi * L[n, i, x], i, 1, n
Simplify[Lagrange[x]];
Print" Langrange Polynomial: ", Lagrange[x]
Print "Simplified Lagrange Polynomial: ", Simplify[Lagrange[x]]
Lagrange Pi  2

Out[164]=
19.0157 - 30 ° + x - 20 ° + x - 42.0757 - 30 ° + x - 10 ° + x + 22.4216 - 20 ° + x - 10 ° + x
7

Langrange Polynomial:
19.0157 - 30 ° + x - 20 ° + x - 42.0757 - 30 ° + x - 10 ° + x + 22.4216 - 20 ° + x - 10 ° + x

Simplified Lagrange Polynomial: 0.9964 + 1.0402 x - 0.638506 x2


Out[168]=
1.0549

QUESTION 8 :

X = {0.1, 0.2, 0.3, 0.4};


Y = {1.40, 1.56, 1.76, 2.00};
n = 4;
For[i = 1, i ≤ n, i ++,
Ln, i, x_ = Productx - Xj  Xi - Xj, j, 1, i - 1 *

Productx - Xj  Xi - Xj, j, i + 1, n


Lagrange[x_] = SumYi * L[n, i, x], i, 1, n
Simplify[Lagrange[x]];
Print" Langrange Polynomial: ", Lagrange[x]
Print "Simplified Lagrange Polynomial: ", Simplify[Lagrange[x]]

Out[173]=
- 233.333 (- 0.4 + x) (- 0.3 + x) (- 0.2 + x) + 780. (- 0.4 + x) (- 0.3 + x) (- 0.1 + x) -
880. (- 0.4 + x) (- 0.2 + x) (- 0.1 + x) + 333.333 (- 0.3 + x) (- 0.2 + x) (- 0.1 + x)

Langrange Polynomial: - 233.333 (- 0.4 + x) (- 0.3 + x) (- 0.2 + x) + 780. (- 0.4 + x) (- 0.3 + x) (- 0.1 + x) -
880. (- 0.4 + x) (- 0.2 + x) (- 0.1 + x) + 333.333 (- 0.3 + x) (- 0.2 + x) (- 0.1 + x)
Simplified Lagrange Polynomial: 1.28 + 1. x + 2. x2 + 1.13687 × 10-13 x3
In[105]:=

You might also like