restart:# DOUBLE INTEGAL ALGORITHM 4.4## To approximate I = double integral ( ( f(x,y) dy dx ) ) with limits# of integration from a to b for x and from c(x) to d(x) for y:## INPUT: endpoints a, b: even positive integers m, n.## OUTPUT: approximation J to I. print(`This is Simpsons Method for double integrals. `):print(`Input the functions F(X,Y), C(X), and D(X) in terms of x and y separated by a space. `):print(`For example: cos(x+y) x^3 x `):F := scanf(`%a`)[1]:print(`F(x,y) = `):print(F):F := unapply(F,x,y):C := scanf(`%a`)[1]:print(`C(x) = `):print(C):C := unapply(C,x):D1 := scanf(`%a`)[1]:print(`D(x) = `):print(D1):D1 := unapply(D1,x):OK := FALSE:while OK = FALSE doprint(`Input lower limit of integration and `):print(`upper limit of integration `):print(`separated by a blank `):A := scanf(`%f`)[1]:B := scanf(`%f`)[1]:print(`a = `):print(A):print(`b = `):print(B):if A > B thenprint(`Lower limit must be less than upper limit `):elseOK := TRUE:fi:od: OK := FALSE:while OK = FALSE doprint(`Input two even positive integers N, M : there will`):print(` be N subintervals for outer `):print(`integral and M subintervals for inner `):print(`integral - separate with blank `):N := scanf(`%d`)[1]:M := scanf(`%d`)[1]:print(`N = `):print(N):print(`M = `):print(M):if M > 0 and N > 0 and M mod 2 = 0 and N mod 2 = 0 thenOK := TRUE:elseprint(`Integers must be even and positive `):fi:od:if OK = TRUE then# Step 1H := (B-A)/N:# Use AN, AE, AO for J(1), J(2), J(3) resp.# End termsAN := 0:# Even termsAE := 0:# Odd termsAO := 0:# Step 2for I1 from 0 to N do# Step 3# Composite Simpson's method for XX := A+I1*H:YA := C(X):YB := D1(X):HX := (YB-YA)/M:# Use BN, BE, BO for K(1), K(2), K(3) resp.# End termsBN := F(X,YA)+F(X,YB):# Even termsBE := 0:# Odd termsBO := 0:# Step 4for J from 1 to M-1 do# Step 5Y := YA+J*HX:Z := F(X, Y):# Step 6if J mod 2 = 0 thenBE := BE+Z:elseBO := BO+Z:fi:od:# Step 7# Use A1 for L, which is the integral of F(X(I),Y) from# C(X(I)) to D(X(I)) by the Composite Simpson's methodA1 := (BN+2*BE+4*BO)*HX/3:# Step 8if I1 = 0 or I1 = N thenAN := AN+A1:elseif I1 mod 2 = 0 thenAE := AE + A1:elseAO := AO + A1:fi:fi:od:# Step 9# Use AC of JAC := (AN + 2 * AE + 4 * AO) * H /3:# Step 10OUP := default:fprintf(OUP,`Double Integrals Using Simpson's Composite Method \134n`):fprintf(OUP,`\134nThe double integral of F from %12.8f to %12.8f is\134n`, A, B):fprintf(OUP,`%12.8f`, AC):fprintf(OUP,` obtained with N := %3d and M := %3d\134n`, N, M):fi:JSFH