Lagrange Interpolation Method Pseudocode

Earlier in Lagrange Interpolation Method Algorithm article we discussed about an algorithm for interpolation using Lagrange interpolation formula. In this article we are going to develop pseudocode for Lagrange Interpolation Formula so that it will be easy while implementing this method using programming languages.

Pseudocode for Lagrange Interpolation Method

1. Start

2. Read Number of Data (n)

3. Read Data:
   For i = 1 to n
     Read Xi and Yi
   Next i

4. Read xp
   
5. Initialize: yp = 0

6. For i = 1 to n
     p = 1
     For j =1 to n
       If i ≠ j 
         p = p * (xp - Xj)/(Xi - Xj)
       End If
     Next j
     yp = yp + p * Yi
   Next i

6. Print yp

7. Stop

-----------------------------------
  Note: All array indexes are assumed to start from 1.

Recommended Readings

  1. Lagrange Interpolation Method Algorithm
  2. Lagrange Interpolation Method Pseudocode
  3. Lagrange Interpolation Method Using C Programming
  4. Lagrange Interpolation Method Using C++