restart:# TRAPEZOIDAL WITH NEWTON ITERATION ALGORITHM 5.8## TO APPROXIMATE THE SOLUTION OF THE INITIAL VALUE PROBLEM:# Y' = F(T,Y), A <= T <= B, Y(A) = ALPHA,# AT (N+1) EQUALLY SPACED NUMBERS IN THE INTERVAL [A,B].## INPUT: ENDPOINTS A,B: INITIAL CONDITION ALPHA: INTEGER N:# TOLERANCE TOL: MAXIMUM NUMBER OF ITERATIONS M AT ANY ONE STEP.## OUTPUT: APPROXIMATION W TO Y AT THE (N+1) VALUES OF T# OR A MESSAGE OF FAILURE.print(`This is the Implicit Trapezoidal Method. `):print(`Input the function F(t,y) in terms of t and y `):print(`For example: y-t^2+1 `):F := scanf(`%a`)[1]:print(`F(x) = `):print(F):FYP := diff(F,y):F := unapply(F,t,y):FYP := unapply(FYP,t,y):OK := FALSE:while OK = FALSE doprint(`Input left and right endpoints separated by blank. `):A := scanf(`%f`)[1]:B := scanf(`%f`)[1]:print(`a = `):print(A):print(`b = `):print(B):if A >= B thenprint(`Left endpoint must be less than right endpoint. `):elseOK := TRUE:fi:od:print(`Input the initial condition. `):ALPHA := scanf(`%f`)[1]:print(`ALPHA = `):print(ALPHA):OK := FALSE:print(`Input a positive integer for the number of subintervals. `):while OK = FALSE doN := scanf(`%d`)[1]:print(`N = `):print(N):if N <= 0 thenprint(`Number must be a postiive integer. `):elseOK := TRUE:fi:od:OK := FALSE:while OK = FALSE doprint(`Input tolerance. `):TOL := scanf(`%f`)[1]:print(`Tolerance = `):print(TOL):if TOL <= 0 thenprint(`Tolerance must be positive. `):elseOK := TRUE:fi:od:OK := FALSE:while OK = FALSE doprint(`Input maximum number of iterations. `):M := scanf(`%f`)[1]:print(`Maximum number of iterations = `):print(M):if M > 0 thenOK := TRUE:elseprint(`Number of iterations must be positive. `):fi:od:if OK = TRUE thenprint(`Choice of output method: `):print(`1. Output to screen `):print(`2. Output to text file `):print(`Please 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]:print(`Entry = `):print(NAME):OUP := fopen(NAME,WRITE,TEXT):elseOUP := default:fi:fprintf(OUP, `IMPLICIT TRAPEZOIDAL METHOD USING NEWTONS METHOD\134n\134n`):fprintf(OUP, ` t w #iter\134n`):# Step 1W := ALPHA:T := A:H := (B-A)/N:fprintf(OUP, `%5.3f %11.8f 0\134n`, T, W):I1 := 1:OK := TRUE:# Step 2while I1 <= N and OK = TRUE do# Step 3XK1 := W+0.5*H*F(T, W):W0 := XK1:J := 1:IFLAG := 0:# Step 4while IFLAG = 0 and OK = TRUE do# Step 5W := W0-(W0-XK1-0.5*H*F(T+H, W0))/(1-0.5*H*FYP(T+H, W0)):# Step 6if abs(W-W0) < TOL then# Step 7IFLAG := 1:T := A+I1*H:fprintf(OUP,`%5.3f %11.8f %3d\134n`, T, W, J):I1 := I1+1:elseJ := J+1:W0 := W:if J > M thenOK := FALSE:fi:fi:od:od:if OK = FALSE thenprint(`Maximum Number of Iterations Exceeded`):fi:# Step 8if OUP <> default thenfclose(OUP):print(`Output file `,NAME,` created successfully`):fi:fi:JSFH