Here is a numeric integration program for the HP 30b. This is a translation of the HP-25 Program Library entry # L19 from 65 Notes V4N2P32 originally by Bandes, Davidson, and Derrick.
Usage:
At LBL 99, key in the function to be integrated. When LBL 99 is executed, the value of the X to be evaluated is in the X register (display) at entry to LBL 99. If you need it again to evaluate the function, it is stored in memory 3. Memories 6 and up are available as well.
At the PRGM location in which this program is stored (at the proper entry in the HP 30b program catalog), Key lower limit, press =, key upper limit, press =. Then press = again to start the program.
This program uses Simpson's rule with a default value of 200 for the number of increments.
The program is VERY fast. To solve the integral of e^x from 0 to 1 using 200 as the number of increments takes less than 2 seconds if this program is program 0 in the HP 30b.
The integral of e^x from 0 to 1 is solved to be 1.71828182849. Value of e minus 1 is 1.71828182846, an error of 3 in the last position.
The integral of SIN(PI*X) from 0 to 1 is solved in about 5-6 seconds with 500 as the number of increments with a solved value of 0.636619772363.
Register usage:
Memory 0 = number of increments, default is 200. Must be an even value.
Memory 1 = lower limit of integration
Memory 2 = upper limit of integration
Memory 3 = value of x being evaluated
Memory 4 = a positive or negative 1, depending on the loop.
Memory 5 = value of integrated function (sum)
Version shown here uses 92 bytes with a checksum of 016.
Improvements can be made to this code. The labels chosen correspond to the line numbers of the GTO statements in the original HP 25 program. Suggestions for improvements:
1) I used LBL 99 for the function to make the function occur at the end of the listing. This could be put into the code right after LBL 06, saving bytes and speeding up execution.
2) Lines 33-35 are to make the stack mimic what was in the HP 25 program. I have not found an easier way to do this, but it is clumsy as is.
3) Lines 36-40 and 48-51 are there to accomplish the following: memory 4 is initialized to zero. The first time through the loop, this should have negative 1 placed into it. Thereafter, the sign of the contents of memory 4 should be switched from negative to positive to negative, etc., each time through the loop. I freely admit this is again clumsy, but it does work.
4) Use something other than Simpsons, especially since it will fail if an endpoint is undefined. Integrating LN(X) from 0 to 1 fails, of course. :-)
Listing:
STO 2
SWAP
STO 1
200
STO 0
0
STO 4
STO 5 ...... LINE 10
RCL 1
STO 3
LBL 06
CALL 99
RCL 2
RCL 1
-
RCL 0
/
STO+ 3 ...... LINE 20
3
/
*
STO+ 5
ANS
RCL 2
RCL 3
-
+
0 ...... LINE 30
?<
GT 49
ROLL DOWN
ROLL DOWN
=
RCL 4
GF 48
RCL 4
LBL 47
+/- ...... LINE 40
STO 4
2
+
*
STO+ 5
RCL 3
GTO 06
LBL 48
RCL 4
1 ...... LINE 50
GTO 47
LBL 49
RCL 5
STOP
LBL 99
E^X
RTN
Enjoy and improve.
Edited: 28 Apr 2010, 3:06 p.m.