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

Lab 8

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)
17 views4 pages

Lab 8

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

Rajshahi University of Engineering & Technology

Department of Electrical & Electronic Engineering


Course No: EEE 3110
Course Title: Computational Methods in Engineering Sessional

Experiment No: 08
Experiment Name: Finding Intermediate Points using Lagrange Interpolating
Polynomials.
SUBMITTED BY SUBMITTED TO

Name: Al-Momin Hosen Sushanto Bosak


Roll: 2101102 Lecturer
Section: B Electrical & Electronic Engineering
Dept.: Electrical & Electronic Engineering Rajshahi University of Engineering &
Session: 2021-2022 Technology (RUET)

Date of Experiment: 19/05/2025


Date of Submission: 26/05/2025
Experiment No: 08
Experiment Name: Finding Intermediate Points using Lagrange Interpolating Polynomials.
Objectives:
1. Understand the Lagrange interpolation method and how it helps estimate values of a
function between known data points.
2. Use MATLAB or Python to apply Lagrange interpolation, find values at intermediate
points, and draw the curve.
3. Check the accuracy of the results by comparing interpolated values with actual function
values.

Theory:
Lagrange Interpolation is a method used to estimate the value of a function at a point when we
only know some values of the function at specific points. This is helpful when the exact formula of
the function is unknown, but we have a few data points.
The idea is to build a single polynomial that passes through all the known points. This polynomial
is called the Lagrange Interpolating Polynomial. If we are given n data points, then the polynomial
will have a degree of n−1.
n
P(x)¿ ∑ yi *Li(x)
i=1

where Li(x) is the Lagrange basis polynomial given by:


n
x−xj
Li ( x )=∏
j =1 xi−xj
j ≠i
This setup ensures that the polynomial passes through all given points exactly.
Lagrange interpolation is easy to use for small datasets and gives accurate results at known points.
However, for larger datasets, it can become less accurate and harder to compute. It is commonly
used in numerical analysis, engineering, and data estimation tasks.

Algorithm:
1. Collect the known data points (x₀, y₀), (x₁, y₁), ..., (xₙ, yₙ).
2. Choose the value of x at which you want to estimate the function (interpolation point).
3. For each data point i from 0 to n:
Create the Lagrange basis polynomial Lᵢ(x) using the formula:
Lᵢ(x) = product of (x - xⱼ) / (xᵢ - xⱼ) for all j ≠ i
4. Multiply each Lᵢ(x) by its corresponding yᵢ value.
5. Add up all the terms from step 4 to get the interpolated polynomial:
P(x) = Σ yᵢ × Lᵢ(x)
6. Substitute the desired x-value into P(x) to get the estimated y-value.
7. Optionally, evaluate P(x) at many points between the first and last x-values to plot the full
curve.
8. Plot the original data points and the interpolated curve for visualization.
MATLAB Code:
clear;
syms X;
x = [1; 6; 4];
y = [0; 1.791579; 1.386294];
P = 0;
n = length(y);

for i = 1:n
L = 1;
for j = 1:n
if j ~= i
L = L * (X - x(j))/(x(i) - x(j));
end
end
P = P + y(i)*L;
end

P= expand(P);
disp('Polynomial:');
disp(P);

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


result=double(subs(P, X,value));
fprintf('\nValue at x =%d is =%.6f\n', value,result);

Output

Discussion:
In this experiment, we used the Lagrange Interpolation method to estimate unknown values
between known data points. It builds a single polynomial that exactly passes through all the given
points. We applied this in MATLAB using three data points of ln(x) to estimate ln(2), and the
result was reasonably accurate. The method is simple and works well for small datasets. However,
if too many points are used or they are spaced unevenly, the polynomial can become unstable and
show large oscillations. Lagrange interpolation is useful when the actual function is unknown but
a few values are known. Still, for larger datasets, other methods like spline interpolation might be
better. This experiment helped us understand how polynomial interpolation works and how it can
be used in practical problems.

You might also like