The first version was written on my Sharp PC1360 with a few bells and whistles to take advantage of its 4line display. I then ported it to the Casio FX880P to see how it would fare on a machine that's about 5x faster, then I finally ported it to the HP41C/DM41.
To run the DM41 version, first write a program that accepts a value in X and returns in X the value of f(X). Make it accessible through a global label that has at most 6 characters.
Then run "INTEG" with the label of the function that you want to integrate in the alpha register. You will be prompted for the lower and upper boundaries of the integration range and the number of "steps" (press R/S after each one). For a number of steps 'n', the program divides the range over which to integrate into 2^n contiguous subranges. 'n' must be a whole number from 0 (no subdivision of the integration range) to 10 (division into 1024 subranges).
For each subrange, it looks at the leftmost and rightmost data points (saving a bit of time knowing that the rightmost point for one subrange is also the leftmost point for the next subrange) and evaluates the middle point too, thus giving it 3 points to work with. It then fits those 3 points that are on the graph for f(x) to a quadratic of the form a.x^2+b.x+c, calculates the integral of that function over the subrange considered and adds it to the running total. In short, it's a bit like Simpson's method.
It uses registers R00 to R15 so don't use them in your program that gives you f(x).
Here's the program:
Code: Select all
LBL "INTEG"
ASTO 12
RCL 10
"LOWER?"
PROMPT
STO 10
RCL 11
"UPPER?"
PROMPT
STO 11
RCL 10
X>Y?
X<>Y
STO 10
X<>Y
STO 11
"STEPS 010?"
LBL 00
PROMPT
ABS
INT
STO 00
10
X<>Y
X>Y?
GTO 00
CLX
STO 03
2
RCL 00
Y^X
STO 01
STO 00
RCL 10
STO 06
XEQ IND 12
STO 09
1
STO 02
LBL 01
RCL 06
STO 04
RCL 09
STO 07
RCL 02
RCL 00
/
RCL 11
RCL 10

*
RCL 10
+
STO 06
XEQ IND 12
STO 09
RCL 06
RCL 04
+
2
/
STO 05
XEQ IND 12
STO 08
RCL 05
RCL 06

RCL 07
RCL 09

*
RCL 04
RCL 06

RCL 08
RCL 09

*

RCL 04
RCL 06

RCL 05
RCL 06

*
RCL 04
RCL 05

*
/
STO 13
CHS
RCL 05
ENTER
*
RCL 06
ENTER
*

*
RCL 08
RCL 09

+
RCL 05
RCL 06

/
STO 14
CHS
RCL 06
*
RCL 09
+
RCL 06
ENTER
*
RCL 13
*

STO 15
RCL 06
RCL 04

*
ST+ 03
RCL 06
ENTER
*
RCL 04
ENTER
*

RCL 14
*
2
/
ST+ 03
RCL 06
ENTER
ENTER
*
*
RCL 04
ENTER
ENTER
*
*

RCL 13
*
3
/
ST+ 03
ISG 02
STO X
DSE 01
GTO 01
CLA
ARCL 12
RCL 03
END