restart:# NEVILLE'S ITERATED INTERPOLATION ALGORITHM 3.1## To evaluate the interpolating polynomial P on the# (n+1) distinct numbers x(0), ..., x(n) at the number x# for the function f:## INPUT: numbers x(0),..., x(n) as XX(0),...,XX(N):# number x: values of f as the first column of Q# or may be computed if function f is supplied.## OUTPUT: the table Q with P(x) = Q(N+1,N+1).print(`This is Neville's Method.\134n `):OK := FALSE:while OK = FALSE doprint(`Choice of input method: `):print(`1. Input entry by entry from keyboard `):print(`2. Input data from a text file `):print(`3. Generate data using a function F `):print(`Choose 1, 2, or 3 please `):FLAG := scanf(`%d`)[1]:print(`Entry = `):print(FLAG):if FLAG = 1 or FLAG = 2 or FLAG = 3 thenOK := TRUE:fi:od:if FLAG = 1 thenOK := FALSE:while OK <> TRUE doprint(`Input n `):N := scanf(`%d`)[1]:print(`n = `):print(N):if N > 0 thenOK := TRUE:for I1 from 0 to N doprint(`Input X(i) and F(X(i)) for i = `):print(I1):print(`separated by a space `):XX[I1] := scanf(`%f`)[1]:Q[I1,0] := scanf(`%f`)[1]:print(`Entries are`):print(XX[I1],Q[I1,0]):od:elseprint(`Number must be a positive integer `):fi:od:fi:if FLAG = 2 thenprint(`Has a text file been created with the data in two columns ? `):print(`Enter Y or N `):A := scanf(` %c`)[1]:print(`Entry = `):print(A):if A = "Y" or A = "y" thenprint(`Input the file name in the form - `):print(`drive:\134 ame.ext `):print(`For example: A:\134\134DATA.DTA `):NAME := scanf(`%s`)[1]:print(`Entry = `):print(NAME):INP := fopen(NAME,READ,TEXT):OK := FALSE:while OK = FALSE doprint(`Input N `):N := scanf(`%d`)[1]:print(`n = `):print(N):if N > 0 thenfor I1 from 0 to N doXX[I1] := fscanf(INP, `%f`)[1]:Q[I1,0] := fscanf(INP, `%f`)[1]:od:fclose(INP):OK := TRUE:elseprint(`Number must be a positive integer `):fi:od:elseprint(`Please create the input file in two column `):print(`form with the X values and `):print(`F(X) values in the corresponding columns. `):print(`The program will end so the input file can `):print(`be created. `):OK := FALSE:fi:fi:if FLAG = 3 thenprint(`Input the function F(x) in terms of x `):print(`For example: cos(x) `):F := scanf(`%a`)[1]:print(`F(x) = `):print(F):F := unapply(F,x):OK := FALSE:while OK = FALSE doprint(`Input n `):N := scanf(`%d`)[1]:print(`n = `):print(N):if N > 0 thenfor I1 from 0 to N doprint(`Input X(i) for i = `):print(I1):XX[I1] := scanf(`%f`)[1]:print(`Entry = `):print(XX[I1]):Q[I1,0] := F(XX[I1]):od:OK := TRUE:elseprint(`Number must be a positive integer `):fi:od:fi:if OK = TRUE thenprint(`Input the point at which the polynomial is to be evaluated `):X := scanf(`%f`)[1]:print(`Value = `):print(X):fi:if OK = TRUE then# Step 1D1[0] := evalf(X-XX[0]):for I1 from 1 to N doD1[I1] := evalf(X-XX[I1]):for J from 1 to I1 doQ[I1,J] := evalf((D1[I1]*Q[I1-1,J-1]-D1[I1-J]*Q[I1,J-1])/(D1[I1]-D1[I1-J])):od:od:# Step 2print(`Select output destination `):print(`1. Screen `):print(`2. Text file `):print(`Enter 1 or 2 `):FLAG := scanf(`%d`)[1]:print(`Entry = `):print(FLAG):if FLAG = 2 thenprint(`Input the file name in the form - drive:\134\134name.ext `):print(`For example: A:\134\134OUTPUT.DTA `):NAME := scanf(`%s`)[1]:OUP := fopen(NAME,WRITE,TEXT):elseOUP := default:fi:fprintf(OUP, `NEVILLE'S METHOD\134n `):fprintf(OUP, `Table for P evaluated at X = %12.8f , follows: \134n`, X):fprintf(OUP, `Entries are XX(I), Q(I,0), ..., Q(I,I) `):fprintf(OUP, `for each I = 0, ..., N where N = %3d\134n\134n`, N): for I1 from 0 to N dofprintf(OUP, `%11.8f `, XX[I1]):for J from 0 to I1 dofprintf(OUP, `%11.8f `, Q[I1,J]):od:fprintf(OUP, `\134n`):od:if OUP <> default thenfclose(OUP):print(`Output file created successfully:`):print(NAME):fi:fi:JSFH