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

Practical 5

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)
7 views7 pages

Practical 5

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
You are on page 1/ 7

interpolation.

wxmx 1 / 7

Practical 5: Langrangian
Interpolation

Name: Sanchit
Course: B.A.Economics(H)
Date: 3-10-24

1 Find the Langrange Interpolating


Polynomial which fits the given data:
f(0)=1,f(1)=3,f(3)=55.
n:read(" Enter the number of data points: ");
for i:1 thru n do
(
x[i]: read("Enter x",i),
f[i]: read("Enter f(x)" ,i, ")")
);
c: read("Enter the value of c where fn is to be estimated ")$
Enter the number of data points: 3; 3
Enter x 1 0;
Enter f(x) 1 ) 1;
Enter x 2 1;
Enter f(x) 2 ) 3;
Enter x 3 3;
Enter f(x) 3 ) 55; done
Enter the value of c where fn is to be estimated 2.5;
interpolation.wxmx 2 / 7

l(j):= product(
if (i=j) then 1
else (x−x[i])/(x[j]−x[i]),
i,1,n);
ratsimp(l(j));

p(x):= sum(l(j)·f[j] , j,1,n);


ratsimp(p(x));

print("approx the val of f at ",c,"is", p(c))$


a:[−1,1,2];
b:[2,7,15];

wxplot2d([p(x),[discrete,a,b]],[x,−1,5]);
n
3 2
x−x x −4 x +3 x
l(j):= i
if i = j then 1 else
3 2
x −x x −4 x +3 x
j i j j j
i=1
n
2
p ( x ) := (l(j) f ) 8 x −6 x+1
j
j=1
approx the val of f at 2.5 is 36.0 [ −1,1,2] [ 2 , 7 , 15 ]
interpolation.wxmx 3 / 7

2 Find the Langrangian Interpolating

Polynomial which fits the given data:

f(0)=7,f(1)=9,f(3)=25,f(5)=117.Also

compute f(4)

n:read(" Enter the number of data points: ");


for i:1 thru n do
(
x[i]: read("Enter x",i),
f[i]: read("Enter f(x)" ,i, ")")
);
c: read("Enter the value of c where fn is to be estimated ")$
Enter the number of data points: 4; 4
Enter x 1 0;
Enter f(x) 1 ) 7;
Enter x 2 1;
Enter f(x) 2 ) 9;
Enter x 3 3;
Enter f(x) 3 ) 25;
Enter x 4 5;
Enter f(x) 4 ) 117; done
Enter the value of c where fn is to be estimated 4;
l(j):= product(
if (i=j) then 1
else (x−x[i])/(x[j]−x[i]),
i,1,n);
ratsimp(l(j));
n

x−x
i
l ( j ) := if i = j then 1 else
x −x
j i
i=1
4 3 2
x − 9 x + 23 x − 15 x
4 3 2
x − 9 x + 23 x − 15 x
j j j j
interpolation.wxmx 4 / 7

p(x):= sum(l(j)·f[j] , j,1,n);


ratsimp(p(x));

n
3 2
p (x ):= 3 x − 8 x + 9 x + 14
(l(j) f )
j 2
j=1

print("approx the val of f at ",c,"is", p(c))$


a:[−1,1,2];
b:[2,7,15];

wxplot2d([p(x),[discrete,a,b]],[x,−1,5]);
approx the val of f at 4 is 57 [−1,1,2] [ 2 , 7 , 15 ]

3 Find the Newton's Interpolating


Polynomial which fits the given data:
f(0.1)=1.4,f(0.2)=1.56,f(0.3)=1.76,f(0.4)=2,f(0.5)=2.28.Also
compute f(0.25)
interpolation.wxmx 5 / 7

n:read(" Enter the number of data points: ");


for i:1 thru n do
(
x[i]: read("Enter x",i),
f[i]: read("Enter f(x)" ,i, ")")
);
c: read("Enter the value of c where fn is to be estimated ")$
5;
Enter the number of data points: 5
Enter x 1 0.1;
Enter f(x) 1 ) 1.4;
Enter x 2 0.2;
Enter f(x) 2 ) 1.56;
Enter x 3 0.3;
Enter f(x) 3 ) 1.76;
Enter x 4 0.4;
Enter f(x) 4 ) 2;
Enter x 5 0.5;
Enter f(x) 5 ) 2.28; done
Enter the value of c where fn is to be estimated 0.25;
l(j):= product(
if (i=j) then 1
else (x−x[i])/(x[j]−x[i]),
i,1,n);
ratsimp(l(j));
n

x−x
i
l ( j ) := if i = j then 1 else
x −x
j i
i=1
rat: replaced -0.5 by -1/2 = -0.5
rat: replaced -0.4 by -2/5 = -0.4
rat: replaced -0.3 by -3/10 = -0.3
rat: replaced -0.2 by -1/5 = -0.2
rat: replaced -0.1 by -1/10 = -0.1
rat: replaced -0.5 by -1/2 = -0.5
rat: replaced -0.4 by -2/5 = -0.4
interpolation.wxmx 6 / 7

rat: replaced -0.3 by -3/10 = -0.3


rat: replaced -0.2 by -1/5 = -0.2
rat: replaced -0.1 by -1/10 = -0.1
5 4 3 2
5000 x − 7500 x + 4250 x − 1125 x + 137 x − 6
5 4 3 2
5000 x − 7500 x + 4250 x − 1125 x + 137 x − 6
j j j j j
p(x):= sum(l(j)·f[j] , j,1,n);
ratsimp(p(x));
n

p ( x ) := (l(j) f )
j
j=1
rat: replaced 583.3333333333333 by 1750/3 = 583.3333333333334
rat: replaced -0.5 by -1/2 = -0.5
rat: replaced -0.4 by -2/5 = -0.4
rat: replaced -0.3 by -3/10 = -0.3
rat: replaced -0.2 by -1/5 = -0.2
rat: replaced -2600.0000000000005 by -2600/1 = -2600.0
rat: replaced -0.5 by -1/2 = -0.5
rat: replaced -0.4 by -2/5 = -0.4
rat: replaced -0.3 by -3/10 = -0.3
rat: replaced -0.1 by -1/10 = -0.1
rat: replaced 4399.999999999999 by 4400/1 = 4400.0
rat: replaced -0.5 by -1/2 = -0.5
rat: replaced -0.4 by -2/5 = -0.4
rat: replaced -0.2 by -1/5 = -0.2
rat: replaced -0.1 by -1/10 = -0.1
rat: replaced -3333.333333333332 by -10000/3 = -3333.3333333333335
rat: replaced -0.5 by -1/2 = -0.5
rat: replaced -0.3 by -3/10 = -0.3
rat: replaced -0.2 by -1/5 = -0.2
rat: replaced -0.1 by -1/10 = -0.1
rat: replaced 950.0000000000002 by 950/1 = 950.0
rat: replaced -0.4 by -2/5 = -0.4
rat: replaced -0.3 by -3/10 = -0.3
rat: replaced -0.2 by -1/5 = -0.2
2
50 x + 25 x + 32
rat: replaced -0.1 by -1/10 = -0.1
25
interpolation.wxmx 7 / 7

print("approx the val of f at ",c,"is", p(c))$


a:[−1,1,2];
b:[2,7,15];

wxplot2d([p(x),[discrete,a,b]],[x,−1,5]);
approx the val of f 0.25
at is 1.6550000000000002 [− 1 ,1 ,2 ]

[2 ,7 ,15 ]

You might also like