## [DM41] Integration

This is the place to discuss the usage of DM1x/DM41 machines and to share any tips & tricks you may have stumbled across.

If discussing a specific model, please ensure that you prefix topic subjects with the model number this way:

[DM41] How to change the number of program steps available
grsbanks
Posts: 856
Joined: Tue Apr 25, 2017 9:23 am
Location: Preston, Lancs, UK
Contact:

### [DM41] Integration

I recently wrote a little tool to perform numerical integration on calculators that don't have the feature built in.

The first version was written on my Sharp PC-1360 with a few bells and whistles to take advantage of its 4-line display. I then ported it to the Casio FX-880P to see how it would fare on a machine that's about 5x faster, then I finally ported it to the HP-41C/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 0-10?"
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``````
Not SwissMicros staff, just an enthusiast.

Thomas Okken
Posts: 609
Joined: Tue May 02, 2017 3:48 pm
Contact:

### Re: [DM41] Integration

Simpson's rule works using second-degree polynomial approximation. Did you mean the Trapezoidal rule?

grsbanks
Posts: 856
Joined: Tue Apr 25, 2017 9:23 am
Location: Preston, Lancs, UK
Contact:

### Re: [DM41] Integration

Thomas Okken wrote:
Sat Apr 07, 2018 9:00 pm
Simpson's rule works using second-degree polynomial approximation. Did you mean the Trapezoidal rule?
You're right, of course. It's over 30 years since I actually studied maths and somehow the idea that the trapezoidal rule was Simpson's rule had got stuck in my brain!
Not SwissMicros staff, just an enthusiast.