Beruflich Dokumente
Kultur Dokumente
(x xi)
f(x) = f(xi)
(xi xj)
j!=i
j=1
=1
Algorithm:
1. Start
2. Read a,n;
3. for i=1 to n in steps of 1 do Read x , f(x)
end for
4. sum = 0
5. for i=1 to n in steps of 1 do
6. product = 1
7. for j=1 to n in steps of 1 do
8. if (j!=i) then
product=product *(a-xj)/(xi-xj)
end for
9. sum=sum+fi*product
end for
10. Print sum
11. stop.
Flowchart:
Problem Statement: Find the Lagrange interpolation polynomial to fit the following data at x=4
x 1.5 3 6
f(x) -0.25 2 20
Output:
Number of tabulated value: 3
Enter values of x & f(x) respectively.
x(1) = 1.5
f(1) = -.25
x(2) = 3
f(2) = 2
x(3) = 6
f(3) = 20
Enter desired value of x : 4
Result: 6
Result: The value of f(x) at x=4 is 6.
Conclusion: In this experiment we learned the MATLAB code of Lagrange interpolation method. Now we can
interpolate a data easily by using Lagrange interpolation formula.