Lagrange
Lagrange
Lagrange
Objectives:
In this experiment we use Lagrange Interpolation method to find the value of
dependent variable y at any point x by using the given data table.
Theory:
The Lagrange interpolation formula is a way to find a polynomial, which
takes on certain values at arbitrary points. Lagrange interpolation
formula gives us the unique polynomial of degree less or equal to n, which
takes specified values at any (n+1) given points. ... Of course for
inverse interpolation we have to ensure that the function is injective (i.e.
one-one) near the value of x being sought.
This is again an Nth degree polynomial approximation formula to the
function f(x), which is known at discrete points xi, i = 0, 1, 2 . . . Nth. If f(x) is
approximated with an Nth degree polynomial then the Nth divided difference
of f(x) constant and (N+1)th divided difference is zero. That is
f [x0, x1, . . . xn, x] = 0
or
Tools:
i) Windows 10 (Operating System)
ii) Matlab 2015a
Methodology:
Algorithm:
1. Start
2. Read number of data (n)
3. Read data Xi and Yi for i=1 ton n
4. Read value of independent variables say xp
Whose corresponding value of dependent say yp is to be
determined.
5. Initialize: yp = 0
6. For i = 1 to n
Set p = 1
For j =1 to n
If i ≠ j then
Calculate p = p * (xp - Xj)/(Xi - Xj)
End If
Next j
Calculate yp = yp + p * Yi
Next i
for i=1:n+1
x(i)=input('Enter the value of xi :\n');
f(i)=input('Enter the value of fi :\n');
end
sum=0;
for i=1:n+1
prodfunc=1;
for j=1:n+1
if j~=i
prodfunc=((prodfunc)*(x1-x(j)))/(x(i)-x(j));
end
end
sum=sum+f(i)*prodfunc;
end
Output:
Enter value of X :
3
Enter value of N :
4
Enter the value of xi :
1.5
Enter the value of fi :
-.25
Enter the value of xi :
3
Enter the value of fi :
2
Enter the value of xi :
6
Enter the value of fi :
20
Enter the value of xi :
9
Enter the value of fi :
4
Enter the value of xi :
5
Enter the value of fi :
8
value of f(3.000000) : 2.000000
Precautions:
1. As we used crack version of matlab, data connections were turned off
during coding.
Discussion:
Reference:
1. https://www.codewithc.com/lagrange-interpolation-in-matlab
2. Steven C. Chapra , Raymond P. Canal, “Numerical Method for Engineers”.