Lagrange Interpolation
Lagrange Interpolation
clc
n=length(x);
yp=0;
for i=1:n
L=1;
for j=1:n
if i~=j
L=L*(xp-x(j))/(x(i)-x(j))
end
end
yp=yp+L*y(i);
end
L = -0.5000
L = -0.1250
L = -0.062500
L = 1.5000
L = 0.7500
L = 0.5625
L = 0.7500
L = 0.3750
L = 0.5625
L = 0.5000
L = 0.1250
L = -0.062500
# Find the value of function at x=1.5 by using Lagrange's interpolation when the data points are
clc
n=length(x);
yp=0;
for i=1:n
L=1;
for j=1:n
if i~=j
L=L*(xp-x(j))/(x(i)-x(j))
end
end
yp=yp+L*y(i);
end
L = 0.3750
L = 0.062500
L = 2.5000
L = -1.2500
L = -0.3125
L = 1.2500
L = 1.8750
L = 0.9375
L = 0.8333
L = 0.6250
L = 0.3125
# Find the value of function at x=1.5 by using Lagrange's interpolation when the data points are
clc
n=length(x);
yp=0;
for i=1:n
L=1;
for j=1:n
if i~=j
L=L*(xp-x(j))/(x(i)-x(j))
end
end
yp=yp+L*y(i);
end
L = 0.5000
L = 0.3750
L = 0.5000
L = 0.7500
L = 0.2500
L = -0.1250