restart:# SIMPSON'S COMPOSITE ALGORITHM 4.1## To approximate I = integral ( ( f(x) dx ) ) from a to b:## INPUT: endpoints a, b: even positive integer n.## OUTPUT: approximation XI to I.print(`This is Simpsons Method. \134n`):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 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 an even positive integer N. `):N := scanf(`%d`)[1]:print(`N = `):print(N):if N > 0 and N mod 2 = 0 thenOK := TRUE:elseprint(`Input must be even and positive `):fi:od:if OK = TRUE then# Step 1H := (B-A)/N:# Step 2XI0 := F(A) + F(B):# Summation of f(x(2*I-1))XI1 := 0.0:# Summation of f(x(2*I))XI2 := 0.0:# Step 3NN := N - 1:for I1 from 1 to NN do# Step 4X := A + I1 * H:# Step 5if I1 mod 2 = 0 then XI2 := XI2 + F(X):elseXI1 := XI1 + F(X): fi:od:# Step 6XI := (XI0 + 2.0 * XI2 + 4.0 * XI1) * H / 3.0:# Step 7print(` The integral of F from a = `):print(A):print(` to b = `):print(B):print(`equals`):print(XI):fi:JSFH