Post Reply 
HP-41 Challenge: Double Integrals by INTEG Recursion
05-28-2016, 12:35 AM (This post was last modified: 05-28-2016 03:33 AM by Ángel Martin.)
Post: #1
HP-41 Challenge: Double Integrals by INTEG Recursion
Well folks, it's time to shake all those dormant brain cells and put them to a worthy task... if you'd agree.

Your mission is to write a program to calculate double integrals, i.e. those where the integrand is a function of two variables, say f(x,y), and where each of them is integrated along an interval - say [y1, y2] and [x1,x2] respectively.

Furthermore, allow for the possibility that the inner integral limits (x1, x2) could be a function of the outer variable (y).

And here is the key requirement: your program must use the INTEG function from the HP41-Advantage, and do it in a RECURSIVE manner - yes, what according to the manual is not possible.. oh well.

Input: the function name in ALPHA, and the four integration limits in the stack - plus a user program to define the function of course.

You can use as many data registers as you want. You can (and will need to) use functions from other modules, such as the AMC_OS/X and (big hint!) the RamPAGE...

I'll post my solution in a few days; it does all the work in just 31 program steps (not counting the function definition).
Six data registers are used, R00-R05. Can you beat that?

Happy recursion!
ÁM
Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Yesterday, 01:25 AM (This post was last modified: Yesterday 01:25 AM by Ángel Martin.)
Post: #2
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
Well, based on the overwhelming response so far (or lack thereof :-) I'll post an article with this subject in case somebody is interested at some point in time.

Cheers,
ÁM
Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Yesterday, 02:33 AM
Post: #3
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
I have not calculated an integral for 35 years, and never even heard of the existence of a double. Smile

Sounds like an interesting programming challenge, I assume you want to swap in and out the buffer of the Advantage module, maintaining more than instance of the buffer. I look forward to your article, maybe I will (as you say) find time to take a stab at it, at some point in the future.

Håkan
Send this user an email Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Yesterday, 04:41 AM
Post: #4
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
(Yesterday 01:25 AM)Ángel Martin Wrote:  Well, based on the overwhelming response so far (or lack thereof :-) I'll post an article with this subject in case somebody is interested at some point in time.

Cheers,
ÁM

OK, I'm interested. It is possible to discuss the method on 15C?!
Thanks!

Csaba
Send this user an email Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Yesterday, 03:03 PM
Post: #5
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
(Yesterday 02:33 AM)hth Wrote:  I have not calculated an integral for 35 years, and never even heard of the existence of a double. Smile

I know what you mean, but it gets even stranger: rumor has it there are even triples!!

(Yesterday 02:33 AM)hth Wrote:  Sounds like an interesting programming challenge, I assume you want to swap in and out the buffer of the Advantage module, maintaining more than instance of the buffer. I look forward to your article, maybe I will (as you say) find time to take a stab at it, at some point in the future.

You're of course on the right track. The trick consists of changing the buffer-14 id# that is created by the first call to INTEG, so that when the second call happens it can create another buffer-14# and do its job on the second variable (X). Changing buffer id's is what function REIDBF does for a living, so there's a match made in heaven.

Timing and sync up are the only details to pay attention to. For instance there cannot be any key assignments (buffer-14# is placed BELOW those!) - The solution is simply to save them in XMEM at the beginning , clear them all, and restore them upon completion.

Cheers,
'AM
Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Yesterday, 03:06 PM (This post was last modified: Yesterday 03:06 PM by Ángel Martin.)
Post: #6
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
(Yesterday 04:41 AM)Csaba Tizedes Wrote:  OK, I'm interested. It is possible to discuss the method on 15C?!

afraid not, at least not using this trick. I don't know the insights of the 15C design but the "buffer" idea is surely not implemented in the same way, if used at all. It's more likely that the OS manages the memory directly using some other approach, not accessible to the user?
Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Yesterday, 08:02 PM
Post: #7
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
(Yesterday 03:06 PM)Ángel Martin Wrote:  
(Yesterday 04:41 AM)Csaba Tizedes Wrote:  OK, I'm interested. It is possible to discuss the method on 15C?!

afraid not, at least not using this trick. I don't know the insights of the 15C design but the "buffer" idea is surely not implemented in the same way, if used at all. It's more likely that the OS manages the memory directly using some other approach, not accessible to the user?

OK, please post here one or two example what you want to show on HP-41 and I can see what kind of multiple integrals you want to calculate.

Thank you!
Csaba
Send this user an email Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Today, 01:53 AM (This post was last modified: Today 01:57 AM by Ángel Martin.)
Post: #8
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
(Yesterday 08:02 PM)Csaba Tizedes Wrote:  OK, please post here one or two example what you want to show on HP-41 and I can see what kind of multiple integrals you want to calculate.

The PPC article in V8N4p31 includes some simple examples - which I'm glad to say are also solved by the recursive approach.

It is embedded in the manual posted below:
Solve/Integrate ROM Manual
Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Today, 02:52 AM
Post: #9
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
Yes, there are triple, quadruple, even quintuple integral examples available on the net. There is no end to the order of integrals, as there is in theory no end to the number of dimensions one can mathematically describe (physically there may be, but then again string / loop theory seems to have come up with quite a few)...

I would like to see the integral program enhanced to do N-order integrals, and would suggest the following quintuple integral be used as a test (since it has been discussed at http://mathfaculty.fullerton.edu/mathews...nk_15.html and they suggest several methods for the solution...

With f(x,y,z,u,w) = sqrt(6-x^2-y^2-z^2-u^2-w^2) evaluate
integ(0,0.7) [ integ(0,0.8) [ integ(0,0.9) [ integ(0,1.0) [ integ(0,1.1) f(x,y,z,u,w) dw ]
du ] dz ] dy ] dx. The answer seems to lie around 1.189.

Greg
Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Today, 02:12 PM
Post: #10
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
(Today 02:52 AM)gjmcclure Wrote:  I would like to see the integral program enhanced to do N-order integrals, and would suggest the following quintuple integral be used as a test (since it has been discussed at http://mathfaculty.fullerton.edu/mathews...nk_15.html and they suggest several methods for the solution...

With f(x,y,z,u,w) = sqrt(6-x^2-y^2-z^2-u^2-w^2) evaluate
integ(0,0.7) [ integ(0,0.8) [ integ(0,0.9) [ integ(0,1.0) [ integ(0,1.1) f(x,y,z,u,w) dw ]
du ] dz ] dy ] dx. The answer seems to lie around 1.189.

This quintuple integral is easy as pie for the HP-71B w/Math ROM using straight out-of-the-box code with no fancy programming or buffer juggling needed.

Assorted results for increasing precision (1E-1, 1E-2, ..., 1E-5) are as follows:

>LIST

10 DEF FNF(X,Y,Z,U,W)=SQR(6-X*X-Y*Y-Z*Z-U*U-W*W)
20 DEF FNG(X,Y,Z,U)=INTEGRAL(0,1.1,K,FNF(X,Y,Z,U,IVAR))
30 DEF FNH(X,Y,Z)=INTEGRAL(0,1,K,FNG(X,Y,Z,IVAR))
40 DEF FNI(X,Y)=INTEGRAL(0,.9,K,FNH(X,Y,IVAR))
50 DEF FNJ(X)=INTEGRAL(0,.8,K,FNI(X,IVAR))

60 FOR I=1 TO 5 @ K=1/10^I @ DISP K,INTEGRAL(0,.7,K,FNJ(IVAR)) @ NEXT I

>DESTROY ALL
>RUN

.1 1.18887862667
.01 1.18887862667
.001 1.18882510429
.0001 1.18878513051
.00001 1.18878333625


so we get from 5 to 8 correct digits give or take a couple ulps, as compared to Mathematica's 1.18878359.

Regards.
V.
.
Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Today, 03:32 PM (This post was last modified: Today 03:32 PM by Ángel Martin.)
Post: #11
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
(Today 02:12 PM)Valentin Albillo Wrote:  
(Today 02:52 AM)gjmcclure Wrote:  With f(x,y,z,u,w) = sqrt(6-x^2-y^2-z^2-u^2-w^2) evaluate
integ(0,0.7) [ integ(0,0.8) [ integ(0,0.9) [ integ(0,1.0) [ integ(0,1.1) f(x,y,z,u,w) dw ]
du ] dz ] dy ] dx. The answer seems to lie around 1.189.

This quintuple integral is easy as pie for the HP-71B w/Math ROM using straight out-of-the-box code with no fancy programming or buffer juggling needed.


Glad this thread pulled you in from your greener pastures Valentín, always a pleasure to read your comments. Sure enough the 71B/MathPac is a vastly superior engine and the recursion functionality there is impressive - yet for a much humbler platform like the 41's the "buffer juggling" is a very elegant work-around - notwithstanding its inherent design limitations of course.

Saludos,
ÁM
Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Today, 03:35 PM (This post was last modified: Today 03:38 PM by Ángel Martin.)
Post: #12
RE: HP-41 Challenge: Double Integrals by INTEG Recursion
FOCAL code shown below. Includes 6 program steps to preserve and restore the Key assignments so they'll be unmodified at the end of the calculations.

Code:

1    LBL "2DITG"    
2    ASTO 05    function name
3    "KEYS"    
4    SAVEKA    sake keys
5    CLKEYS    clear ka space
6    STO 04    x2
7    RDN    
8    STO 03    x1
9    RDN    
10    STO 02    y2
11    RDN     
12    STO O1    y1
13    13    
14    B?         leftovers?
15    CLB        yes, delete
16    RCL 01    y1
17    RCL 02    y2
18    "*2D"    F(y)
19    INTEG    outer integral
20    "KEYS"    
21    GETKA    restore keys
22    CLA     
23    ARCL 05    function name
24    RTN        final result in X.
25    LBL "*2D"    
26    STO 00    y
27    14,013    
28    REIDBF    change buffer id#
29    RCL 03    x1
30    RCL 04    x2
31    CLA     
32    ARCL 05    function name
33    INTEG    inner integral
34    13,014    
35    REIDBF    change buffer id#
36    RDN            solution to X
37    END
Send this user a private message Find all posts by this user
Quote this message in a reply Quote this post Report this post to a moderator
Post Reply 




User(s) browsing this thread: Namir