Not all real functions can be conveniently expressed as an algebraic formula, of course. Sometimes we only have values from a graph or table that we have to integrate. In this case, we can store a function values in an array; with a 2K machine it is not unreasonable to store a function with 100 data points. The following program will integrate an arbitrary function, with resolution limited only be available memory space. After the program is a sample run illustrating a possible application. You can SAVE the program and data to tape by pressing “S” when output appears.
2 SLOW
5 PRINT TAB 11;"[illegible]";TAB 10;"[illegible]"
10 PRINT ,,"NO. OF DIVS (MUST BE EVEN)=";
15 INPUT D
20 IF INT (D/2)<>D/2 THEN GOTO 15
25 PRINT D
30 DIM A(D+1)
40 PRINT "X(0)=";
50 INPUT X0
60 PRINT X0
70 PRINT "X(F)=";
80 INPUT XF
90 PRINT XF
100 PRINT ,,"INPUT FUNCTION VALUES";AT 20,0;"DIV X=","Y="
110 FOR B=0 TO D
115 LET X=X0+(XF-X0)*B/D
120 SCROLL
130 PRINT AT 21,31;" ";AT 21,0;B;TAB 4;X;AT 21,16;"?"
140 INPUT A(B+1)
145 PRINT AT 21,16;A(B+1)
150 NEXT B
160 FAST
170 PAUSE 40000
200 LET C=0
210 LET A=0
220 LET Y=A(1)
230 LET A=Y+A
240 LET C=C+1
250 LET Y=A(C+1)
260 LET A=Y*4+A
270 LET C=C+1
280 LET Y=A(C+1)
290 LET A=Y+A
300 IF C<D THEN GOTO 230
310 LET S=A*(XF-X0)/D/3
320 CLS
330 PRINT "[illegible]=";S
340 PRINT ,,"[illegible]=";S/(XF-X0)
350 PRINT ,,"SAVE - ""S"""
360 PAUSE 40000
370 IF INKEY$="S" THEN SAVE "ARBIN[illegible]"
DIV X= Y= 0 0 0 1 0.5 0 2 1 0 3 1.5 0 4 2 0 5 2.5 0 6 3 0 7 3.5 0 8 4 0.5 9 4.5 1.7 10 5 2.9 11 5.5 4.8 12 6 7.35 13 6.5 10.2 14 7 12.5 15 7.5 14 16 8 17.3 17 8.5 18.3 18 9 18.8 19 9.5 19.5 20 10 20.3 21 10.5 22.6 22 11 25.8 23 11.5 29.5 24 12 32.3 25 12.5 35.5 26 13 35.7 27 13.5 34.2 28 14 31.3 29 14.5 28.8 30 15 27.7 31 15.5 28.2 32 16 27.8 33 16.5 24.3 34 17 21.5 35 17.5 18.3 36 18 12.2 37 18.5 7.5 38 19 4.2 39 19.5 2.1 40 20 0.4 41 20.5 0 42 21 0 43 21.5 0 44 22 0 45 22.5 0 46 23 0 47 23.5 0 48 24 0
SAMPLE RUN: Let’s assume we’re interested in finding the total energy produced by a solar panel over the course of a day. We can measure the panel’s output, in watts, at regular intervals (e.g. every half-hour) to arrive at the table shown. The results show that this solar panel put out a total of 299.18 watt-hours on this particular day, with an average output of 12.466 watts over the 24-hour period.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.