clc;clear; format long;
x=[0,1,2];y=[1,2,9];xp=1.5;
n=length(x);yp=0;
for i=1:n
L=1;
for j=1:n
if j~=i
L=L*(xp-x(j))/(x(i)-x(j));
end
end
yp=yp+y(i)*L;
end
fprintf('y at x=1.5=%.8f\n',yp);
clc;
clear;
format long;
x = [0, 0.5, 1];y = [0, 0.4794, 0.8415];xp = 0.8;
n = length(x);yp = 0;
for i = 1:n
L = 1;
for j = 1:n
if j ~= i
L = L * (xp - x(j)) / (x(i) - x(j));
end
end
yp = yp + y(i) * L;
end
fprintf('y(0.8) = %.8f\n', yp);
clc;clear; format long;
x=[0,1,2];y=[1,2,9];xp=1.5;
n=length(x);yp=0;
for i=1:n
L=1;
for j=1:n
if j~=i
L=L*(xp-x(j))/(x(i)-x(j));
end
end
yp=yp+y(i)*L;
end
fprintf('y at x=1.5=%.8f\n',yp);
clc;
clear;
format long;
x = [0, 0.5, 1];y = [0, 0.4794, 0.8415];xp = 0.8;
n = length(x);yp = 0;
for i = 1:n
L = 1;
end
fprintf('y(0.8) = %.8f\n', yp);