Practical 5
Practical 5
wxmx 1 / 7
Practical 5: Langrangian
Interpolation
Name: Sanchit
Course: B.A.Economics(H)
Date: 3-10-24
l(j):= product(
if (i=j) then 1
else (x−x[i])/(x[j]−x[i]),
i,1,n);
ratsimp(l(j));
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
f(0)=7,f(1)=9,f(3)=25,f(5)=117.Also
compute f(4)
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
n
3 2
p (x ):= 3 x − 8 x + 9 x + 14
(l(j) f )
j 2
j=1
wxplot2d([p(x),[discrete,a,b]],[x,−1,5]);
approx the val of f at 4 is 57 [−1,1,2] [ 2 , 7 , 15 ]
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
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
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 ]