Professional Documents
Culture Documents
Task-1:: Faculty of Engineering Sciences and Technology Hamdard Institute of Engineering & Technology Hamdard University
Task-1:: Faculty of Engineering Sciences and Technology Hamdard Institute of Engineering & Technology Hamdard University
1. Find y at x = 0.6 with the help of Lagrange and Newton divided difference
method that passes through the following data points:
function fi = Lagran_(x,f,xi)
fi=zeros(size(xi));
np1=length(f);
for i=1:np1
z=ones(size(xi));
for j=1:np1
if i~=j,
z=z.*(xi-x(j))/(x(i)-x(j));
end
end
fi=fi+z*f(i);
end
x y
0 0.9996
0.25 0.7609
0.50 0.6654
0.75 0.5555
1.00 0.4433
where y(x) is a . function of x. Find the values of x that satisfy y = 0.8, 0.6, 0.5,
and 0.4, respectively, using Lagrange interpolation.
Task-2:
function fi = Lagran_(x,f,xi)
fi=zeros(size(xi));
np1=length(f);
for i=1:np1
z=ones(size(xi));
for j=1:np1
if i~=j,
z=z.*(xi-x(j))/(x(i)-x(j));
FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY
Hamdard Institute of Engineering & Technology
Hamdard University
end
end
fi=fi+z*f(i);
end
Output:
3. Two material properties of carbon monoxide gas are given in the following table:
T Beta Alpha
300 1.33e3 0.2128e4
400 1.50e3 0.4625e4
500 0.86e3 0.6384e4
600 0.65e3 0.7190e4
function fi = Lagran_(x,f,xi)
fi=zeros(size(xi));
np1=length(f);
for i=1:np1
z=ones(size(xi));
for j=1:np1
if i~=j,
z=z.*(xi-x(j))/(x(i)-x(j));
end
end
FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY
Hamdard Institute of Engineering & Technology
Hamdard University
fi=fi+z*f(i);
end
Output:
Alpha Values:
function fi = Lagran_(x,f,xi)
fi=zeros(size(xi));
np1=length(f);
for i=1:np1
z=ones(size(xi));
for j=1:np1
if i~=j,
z=z.*(xi-x(j))/(x(i)-x(j));
end
end
fi=fi+z*f(i);
end