Embed presentation
Download to read offline
![function[p]=langrange(x,xint,y)
x=[1 2 5];
y=[1 4 10];
xint=3;
n=size(x,2)
L=ones(n,size(xint,2));
if (size(x,2)~=size(y,2));
fprint('error x and y have same values')
else
for i=1:n
for j=1:n
if(i~=j)
L(i,:)=L(i,:)*(xint-x(j))/(x(i)-x(j));
end
end
end
p=0;
for i=1:n
p=p+y(i)*(L(i,:));
end
end
--------------------
Taimoor Gondal
Asim Zahid
Umar Cheema](https://image.slidesharecdn.com/langrangemethode-180219135908/75/Langrange-method-for-MATLAB-Code-1-2048.jpg)

The document presents a MATLAB function for polynomial interpolation using Lagrange's method. It defines input arrays for x and y values, an interpolation point xint, and calculates the corresponding polynomial value p. The function checks for equal sizes of x and y and computes the Lagrange basis polynomials followed by the final polynomial value.
![function[p]=langrange(x,xint,y)
x=[1 2 5];
y=[1 4 10];
xint=3;
n=size(x,2)
L=ones(n,size(xint,2));
if (size(x,2)~=size(y,2));
fprint('error x and y have same values')
else
for i=1:n
for j=1:n
if(i~=j)
L(i,:)=L(i,:)*(xint-x(j))/(x(i)-x(j));
end
end
end
p=0;
for i=1:n
p=p+y(i)*(L(i,:));
end
end
--------------------
Taimoor Gondal
Asim Zahid
Umar Cheema](https://image.slidesharecdn.com/langrangemethode-180219135908/75/Langrange-method-for-MATLAB-Code-1-2048.jpg)