0% found this document useful (0 votes)
14 views4 pages

Lagrange Interpolation

The document describes the process of finding function values using Lagrange's interpolation for three different sets of data points. It includes MATLAB code snippets that take input for x values, corresponding f(x) values, and a point to obtain the interpolated value. The results of the interpolation for each set of points are also provided.

Uploaded by

23043563034
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Lagrange Interpolation

The document describes the process of finding function values using Lagrange's interpolation for three different sets of data points. It includes MATLAB code snippets that take input for x values, corresponding f(x) values, and a point to obtain the interpolated value. The results of the interpolation for each set of points are also provided.

Uploaded by

23043563034
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

# Find the value of function at x=2.

5 by using Lagrange's interpolation when the data points are

# (1,1), (2,4), (3,9), (4,16)

clc

x=input('Enter the value of x:');

y=input('Enter the value of f(x):');

xp=input('Enter the value of the point to obtain:');

n=length(x);

yp=0;

for i=1:n

L=1;

for j=1:n

if i~=j

%Lagrange's Interpolation formula

L=L*(xp-x(j))/(x(i)-x(j))

end

end

yp=yp+L*y(i);

end

fprintf('Interpolational value at x=%2.3f',yp)

Enter the value of x :[1 2 3 4]

Enter the value of f(x) :[1 4 9 16]

Enter the value of the point to obtain :2.5

L = -0.5000

L = -0.1250

L = -0.062500

L = 1.5000

L = 0.7500

L = 0.5625

L = 0.7500

L = 0.3750
L = 0.5625

L = 0.5000

L = 0.1250

L = -0.062500

Interpolational value at x=6.250>>

# Find the value of function at x=1.5 by using Lagrange's interpolation when the data points are

# (-1,5), (0,1), (1,1), (2,11)

clc

x=input('Enter the value of x:');

y=input('Enter the value of f(x):');

xp=input('Enter the value of the point to obtain:');

n=length(x);

yp=0;

for i=1:n

L=1;

for j=1:n

if i~=j

%Lagrange's Interpolation formula

L=L*(xp-x(j))/(x(i)-x(j))

end

end

yp=yp+L*y(i);

end

fprintf('Interpolational value at x=%2.3f',yp)

Enter the value of x :[-1 0 1 2]

Enter the value of f(x) :[5 1 1 11]

Enter the value of the point to obtain :1.5


L = -1.5000

L = 0.3750

L = 0.062500

L = 2.5000

L = -1.2500

L = -0.3125

L = 1.2500

L = 1.8750

L = 0.9375

L = 0.8333

L = 0.6250

L = 0.3125

Interpolational value at x=4.375>>

# Find the value of function at x=1.5 by using Lagrange's interpolation when the data points are

# (1, ln1), (2, ln2), (3, ln3)

clc

x=input('Enter the value of x:');

y=input('Enter the value of f(x):');

xp=input('Enter the value of the point to obtain:');

n=length(x);

yp=0;

for i=1:n

L=1;

for j=1:n

if i~=j

%Lagrange's Interpolation formula

L=L*(xp-x(j))/(x(i)-x(j))

end

end
yp=yp+L*y(i);

end

fprintf('Interpolational value at x=%2.3f',yp)

Enter the value of x: [1 2 3]

Enter the value of f(x): [0 0.69314718 1.098612289]

Enter the value of the point to obtain :1.5

L = 0.5000

L = 0.3750

L = 0.5000

L = 0.7500

L = 0.2500

L = -0.1250

Interpolational value at x=0.383>>

You might also like