You are on page 1of 1

X = input('Enter list of abscissas: ');

Y = input('Enter list of ordinates: ');


P0 = input('Enter the point at which you want approximation: ');
n = length(X);
L = zeros(n,n);
for i = 1:n
V = 1;
for j = 1:n
if i ~= j
V = conv(V,poly(X(j)))/(X(i)-X(j));
end
end
L(i,:) = V*Y(i);
end
L;
P = sum(L);
F = flip(P);
for k = n :-1:2
fprintf('+(%.2fx^%d)',F(k),k-1)

end
fprintf('+(%.2f)\n',F(1))
A = polyval(P,P0)
x = linspace(X(1),X(n),100);
y = polyval(P,x);
plot(x,y,'r')
hold on
plot(X,Y,'o')

You might also like