restart:# RUNGE-KUTTA (ORDER 4) ALGORITHM 5.2## TO APPROXIMATE THE SOLUTION TO 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.## OUTPUT: APPROXIMATION W TO Y AT THE (N+1) VALUES OF T.print(`This is the Runge-Kutta Order Four 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(t,y) = `):print(F):F := unapply(F,t,y):OK := FALSE:while OK = FALSE doprint(`Input left and right endpoints separated by blank`):A := scanf(`%f`)[1]:print(`a = `):print(A):B := scanf(`%f`)[1]:print(`b = `):print(B):if A >= B then print(`Left endpoint must be less than right endpoint`):elseOK := TRUE:fi:od:print(`Input the initial condition`):ALPHA := scanf(`%f`)[1]:print(`y(a) = `):print(ALPHA):OK := FALSE:while OK = FALSE doprint(`Input a positive integer for the number of subintervals`):N := scanf(`%d`)[1]:print(`N = `):print(N):if N <= 0 thenprint(`Number must be a positive integer`):elseOK := TRUE: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(`Your choice is `):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(`File name is `):print(NAME):OUP := fopen(NAME,WRITE,TEXT):elseOUP := default:fi:fprintf(OUP, `RUNGE-KUTTA FOURTH ORDER METHOD\134n\134n`):fprintf(OUP, ` t w\134n\134n`):# Step 1H := (B-A)/N:T := A:W := ALPHA:fprintf(OUP, `%5.3f %11.7f\134n`, T, W):# Step 2for I1 from 1 to N do# Step 3# Use K1, K2, K3, K4 for K(1), K(2), K(3), K(4) resp.K1 := H*F(T,W):K2 := H*F(T+H/2.0, W+K1/2.0):K3 := H*F(T+H/2.0, W+K2/2.0):K4 := H*F(T+H,W+K3):# Step 4# Compute W(I)W := W+(K1+2.0*(K2+K3)+K4)/6.0:# Compute T(I)T := A+I1*H:# Step 5fprintf(OUP, `%5.3f %11.7f\134n`, T, W):od:# Step 6if OUP <> default thenfclose(OUP):print(`Output file`,NAME,` created successfully`):fi:fi:JSFH