restart:# FIXED-POINT ALGORITHM 2.2## To find a solution to p = g(p) given an# initial approximation p0## INPUT: initial approximation p0: tolerance TOL:# maximum number of iterations NO.## OUTPUT: approximate solution p or # a message that the method fails.print(`This is the Fixed-Point Method.\134n`):print(`Input the function G(x) in terms of x\134n`):print(`For example: cos(x)\134n`):G := scanf(`%a`)[1]:print(G):G := unapply(G,x):OK := FALSE:print(`Input initial approximation\134n`):P0 := scanf(`%f`)[1]: print(`Initial approximation = `):print(P0):while OK = FALSE doprint(`Input tolerance\134n`):TOL := scanf(`%f`)[1]:print(`Tolerance = `):print(TOL):if TOL <= 0 thenprint(`Tolerance must be positive\134n`):else OK := TRUE:fi:od:OK := FALSE:while OK = FALSE doprint(`Input maximum number of iterations - no decimal point\134n`):NO := scanf(`%d`)[1]:print(`Maximum number of iterations = `):print(N0):if NO <= 0 thenprint(`Must be positive integer\134n`):else OK := TRUE:fi:od:if OK = TRUE thenprint(`Select output destination\134n`):print(`1. Screen\134n`):print(`2. Text file\134n`):print(`Enter 1 or 2\134n`):FLAG := scanf(`%d`)[1]:print(`Entry = `):print(FLAG):if FLAG = 2 thenprint(`Input the file name in the form - drive:\134\134name.ext\134n`):print(`For example: A:\134\134OUTPUT.DTA\134n`):NAME := scanf(`%s`)[1]:print(`File name is `):print(NAME):OUP := fopen(NAME,WRITE,TEXT):elseOUP := default:fi:print(`Select amount of output\134n`):print(`1. Answer only\134n`):print(`2. All intermediate approximations\134n`):print(`Enter 1 or 2\134n`):FLAG := scanf(`%d`)[1]:print(`Entry = `):print(FLAG):fprintf(OUP, `FIXED-POINT METHOD\134n`):if FLAG = 2 thenfprintf(OUP, ` I P\134n`):fi:# Step 1I1 := 1:OK := TRUE:# Step 2while I1 <= NO and OK = TRUE do# Step 3# Compute P(I)P := G(P0):if FLAG = 2 thenfprintf(OUP, `%3d %15.8e\134n`, I1, P):fi:# Step 4if abs(P-P0) < TOL then# Procedure completed successfullyfprintf(OUP, `\134nApproximate solution P = %12.8f\134n`, P):fprintf(OUP, `Number of iterations = %3d`, I1):fprintf(OUP, ` Tolerance = %14.8e\134n`,TOL):OK := FALSE:else# Step 5I1 := I1+1:# Step 6# Update P0P0 := P:fi:od:if OK = TRUE then# Step 7# Procedure completed unsuccessfullyfprintf(OUP, `\134nIteration number %3d`, NO):fprintf(OUP, ` gave approximation %12.8f\134n`, P):fprintf(OUP, `not within tolerance %14.8e\134n`,TOL):fi:if OUP <> default thenfclose(OUP):print(`Output file `,NAME,` created successfully`):fi:fi:JSFH