10 PRINT "INTEGRATION: SIMPSON'S RULE"
20 PRINT
30 PRINT "SELECTION: 1=KNOWN FORMULA, O=UNKNOWN FORMULA";
40 INPUT S
49 REM - IF FUNCTION IS KNOWN ENTER AT LINE 50 (DEFFNC(x)="FUNCTION")
50 DEF FNC(X)=X
60 PRINT "LOWER, UPPER LIMIT OF INTEGRATION";
70 INPUT A,B
80 PRINT "INCREMENT OF X";
90 INPUT X1
98 REM - INCREMENT MUST DIVIDE INTERVAL EQUAL SUBINTERVALS;
99 REM - IF NOT, CHANGE INCREMENT
100 IF (B-A)/X1<>INT((B-A)/X1) THEN 80
110 IF S=1 THEN 150
119 REM - FORMULA NOT KNOWN; ENTER FUNCTION VALUE AT INTEGRATION LIMITS
120 PRINT "FIRST, LAST VALUE OF F(x)";
130 INPUT Y1,Y2
140 GOTO 170
149 REM - FORMULA KNOWN; CALCULATE F(x) AT INTEGRATION LIMITS
150 Y=FNC(A)
160 Y2=FNC(B)
170 C=0
180 D=0
189 REM - LOOP FOR EACH SUBINTERVAL
190 FOR I=1 TO (B-A)/X1-.5
200 IF S=1 THEN 240
209 REM - ENTER KNOWN FUNCTION VALUE AT EACH INTERVAL
210 PRINT "VALUE OF F(x) AT INTERVAL";I;"(x=";A+I*X1;")";
220 INPUT Y
230 GOTO 250
239 REM - CALCULATE F(x) AT EACH SUBINTERVAL
240 Y=FNC(A+I*X1)
249 REM - INTERVAL EVEN OR ODD?
250 IF I/2=INT(I/2) THEN 280
259 REM - SUM ALL ODD-INTERVAL FUNCTION VALUES
260 C=C+Y
270 GOTO 290
279 REM - SUM ALL EVEN INTEGRAL FUNCTION VALUES
280 D=D+Y
290 NEXT I
299 REM - COMPUTE INTEGRAL, PRINT
300 PRINT "INTEGRAL IS";X1/3*(Y1+4*C+2*D+Y2)
310 END
