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 do print(`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 then OK := TRUE: fi: od: if FLAG = 1 then OK := FALSE: while OK <> TRUE do print(`Input n `): N := scanf(`%d`)[1]:print(`n = `):print(N): if N > 0 then OK := TRUE: for I1 from 0 to N do print(`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: else print(`Number must be a positive integer `): fi: od: fi: if FLAG = 2 then print(`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" then print(`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 do print(`Input N `): N := scanf(`%d`)[1]:print(`n = `):print(N): if N > 0 then for I1 from 0 to N do XX[I1] := fscanf(INP, `%f`)[1]: Q[I1,0] := fscanf(INP, `%f`)[1]: od: fclose(INP): OK := TRUE: else print(`Number must be a positive integer `): fi: od: else print(`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 then print(`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 do print(`Input n `): N := scanf(`%d`)[1]:print(`n = `):print(N): if N > 0 then for I1 from 0 to N do print(`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: else print(`Number must be a positive integer `): fi: od: fi: if OK = TRUE then print(`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 1 D1[0] := evalf(X-XX[0]): for I1 from 1 to N do D1[I1] := evalf(X-XX[I1]): for J from 1 to I1 do Q[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 2 print(`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 then print(`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): else OUP := 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 do fprintf(OUP, `%11.8f `, XX[I1]): for J from 0 to I1 do fprintf(OUP, `%11.8f `, Q[I1,J]): od: fprintf(OUP, `\134n`): od: if OUP <> default then fclose(OUP): print(`Output file created successfully:`):print(NAME): fi: fi: STxUaGlzfmlzfk5ldmlsbGUnc35NZXRob2QufCt+RzYi STlDaG9pY2V+b2Z+aW5wdXR+bWV0aG9kOn5HNiI= SUcxLn5JbnB1dH5lbnRyeX5ieX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FbnRyeX49fkc2Ig== IiIi NEVILLE'S METHOD Table for P evaluated at X = 1.50000000 , follows: Entries are XX(I), Q(I,0), ..., Q(I,I) for each I = 0, ..., N where N = 3 1.00000000 0.76519770 1.30000000 0.62008600 0.52334487 1.60000000 0.45540220 0.51029680 0.51247148 1.90000000 0.28181860 0.51326340 0.51128567 0.51181269 JSFH