Lagrange Interpolation Method Pseudocode

Table of Contents

This article explains pseudocode for interpolating intermediate value using Lagrange interpolation formula.

Pseudocode: Lagrange Interpolation

Pseudocode for Lagrange interpolation method requires following steps in order to interpolate intermediate value with the help of computer:

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.