clc
clear
% In the name of Allah
% This Program interpolates using Lagrange polynomial
% programmed by WWW.Chemical-Eng.blog.ir 

N=input('Enter the order of polynomial you want to produce: ');

for i=1:N+1
    x(i)=input('Insert your next X data= ');
    y(i)=input('insert your next y data= ');
end
xstar=input('Enter the value you want to interploate: ');
disp(' ')

Pn=0;
for j=1:N+1;
    L(j)=1;
    
for i=1:N+1
    
    if i~=j
    L(j)=L(j)*(xstar-x(i))/(x(j)-x(i));
    end
    
end
L(j)=L(j)*y(j);

Pn=Pn+L(j);
end
disp('The interpolated y-value of xstar is equal to: '); Pn

    