You are on page 1of 3

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:

X 0 0.4 0.8 1.2


Y 1.0 1.491 2.225 3.320
Task-1:

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

2. Suppose a functional relation y = y(x) is given in a tabular form as in

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

where T is the temperature in Kelvin, Beta (or β) is the thermal expansion


coefficient (1/K), and Alpha (or ᾀ) is the thermal diffusivity (m2/s). Using Newton
divided difference method find the properties for T= 321 and 571, respectively.
Task-3:
Beta 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
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

You might also like