Write an algorithm to compute the value of a function using Lagrange’s interpolation.
The interpolating polynomial is:
1. Start
2. Read number of data (n)
3. Read data Xi and Yi for i=1 to n
4. Read value of independent variables say xp
whose corresponding value of dependent variables 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
6. Display value of yp as interpolated value.
7. Stop
Comments