2 COMMENT SIMPSON-S RULE INTEGRATION PROCEDURE, TRANSLATED TO BALGOL
2         FROM THE EXAMPLE IN THE PRELIMINARY IAL REPORT;
2
2 COMMENT
2     EXAMPLE.. INTEGRATION OF A FUNCTION F(X) BY SIMPSON-S RULE. THE
2     VALUES OF F(X) ARE SUPPLIED BY AN ASSUMED EXISTENT FUNCTION
2     ROUTINE. THE MESH SIZE IS HALVED UNTIL TWO SUCCESSIVE SIMPSON
2     SUMS AGREE WITHIN A PRESCRIBED ERROR. DURING THE MESH REDUCTION
2     F(X) IS EVALUATED AT MOST ONCE FOR ANY X. A VALUE V GREATER THAN
2     THE MAXIMUM ABSOLUTE VALUE ATTAINED BY THE FUNCTION ON THE
2     INTERVAL IS REQUIRED FOR INITIALZING;
2
2 PROCEDURE SIMPS(A, B, DELTA, V;; F());
2     COMMENT A, B ARE THE MIN AND MAX, RESP. OF THE POINTS DEF.
2     INTERVAL OF INTEG. F() IS THE FUNCTION TO INTEGRATED.
2     DELTA IS THE PERMISSIBLE DIFFERENCE BETWEEN TO SUCCESSIVE SIMPSON
2     SUMS. V IS GREATER THAN THE MAXIMUM ABSOLUTE VALUE OF F ON A, B;
2   BEGIN
2   COMMENT -- MONITOR IBAR, N, H, J, S, K, I;
2   INTEGER K, N;
2
2   IBAR = V(B-A);
2   N = 1;
2   H = (B-A)/2;
2   J = H(F(A) + F(B));
2
2 J1..
2   S = 0;
2   FOR K = (1, 1, N);
2     S = S + F(A + (2K-1)H);
2
2   I = J + 4H.S;
2   IF DELTA LSS ABS(I-IBAR);
2     BEGIN
2     IBAR = I;
2     J = (I+J)/4;
2     N = 2N;
2     H = H/2;
2     GO TO J1
2     END;
2
2   SIMPS() = I/3;
2   RETURN;
2   END SIMPS();
2
2 FUNCTION TORADS(X) = 3.1415926X/180;
2
2 FUNCTION DARCTAN(X) = 1/(X*2 + 1);
2
2 PROCEDURE LOGISTICSIGMOID(X);
2   BEGIN
2   LOGISTICSIGMOID() = 1/(1 + EXP(-X));
2   RETURN;
2   END LOGISTICSIGMOID();
2
2 SUM = SIMPS(TORADS(30.0), TORADS(90.0), 0.00001, 2.0;; SIN());
2 WRITE(;; RESULT, F1);
2 SUM = SIMPS(0.0, 1.0, 1**-5, 2.0;; DARCTAN());
2 WRITE(;; RESULT, F2);
2 SUM = SIMPS(0.5, 3.0, 1**-5, 2.0;; LOGISTICSIGMOID());
2 WRITE(;; RESULT, F3);
2
2 OUTPUT RESULT(SUM);
2 FORMAT F1(*SINE INTEGRAL =    *,X10.6,W0),
2        F2(*DARCTAN INTEGRAL = *,X10.6,W0),
2        F3(*LOGISTIC INTEGRAL =*,X10.6,W0);
2 FINISH;