▼
Posts: 1,792
Threads: 62
Joined: Jan 2005
RPL "gurus" 
I have a small challenge for you  a straightforward problem that is easy to solve on an RPNbased HP with SOLVE and INTEGrate, but has caused me to give up in frustration using a 48G.
The task: Write a completely selfcontained program that calculates the area between two curves over some region of interest. The program must find both the lower and upper limits of integration using automated rootfinding capability (ROOT on the 48/49; SOLVE(R) on RPNbased calcs), then integrate using those limits.
Example:
Find the area between f(x) and g(x) for the range of x such that f(x) > g(x).
f(x) = sin(x)
g(x) = (x1.5)^2  1
(x is in radians.)
The area is the integral of positive values of [f(x)g(x)]. The limits of integration are the solutions to [f(x)g(x)] = 0. Programming [f(x)g(x)] and executing at x = 0, 1, 2, and 3 shows that zerocrossings exist between 0 and 1, and between 2 and 3.
Here is a program for the 15C and 34C that calculates and stores the following answers:
x_lower = 0.343717
x_upper = 2.696175
Area = 3.110575
LBL "A" LBL "B" (execution)
0 SIN RAD
ENTER X<>Y FIX 5
1 1 GSB "A"
SOLVE "B" .
STO 0 5
2 
ENTER X^2
3 1
SOLVE "B" 
STO 1 
RCL 0 RTN
X<>Y
INTEG "B"
STO 2
RTN
Programs that are quite similar in approach and complexity could be written for the 32S/ii, 42S, and 41C with Advantage Pac to solve this problem.
Can anyone show me how it is done on a 48 or 49series calculator? My attempts have failed due to "syntax errors" in the integration command inside a program. (I have learned how to use integration with an argument list inside an expression fed to ROOT, but this one is stumping me.)
Thanks,
Karl S.
Edited: 15 Feb 2004, 10:32 p.m.
▼
Posts: 362
Threads: 30
Joined: Jul 2005
I store SIN(X) in F
I store SQ(X1.5)1 in G
I use the following program:
<< RAD F G  DUP 'EQ' STO EQ 'X' 0 XNUM ROOT OVER 'X' 3 ROOT ROT 'X' S >>
Where S is the integral function
I get after a while
3.1105...
There may be faster and better ways to do it but I hope this helps
Arnaud
▼
Posts: 362
Threads: 30
Joined: Jul 2005
After a bit of looking I removed some useless parts. This is a bit better but still not best:
<< RAD F G  DUP 'X' 0 ROOT OVER 'X' 3 ROOT ROT 'X' S >>
S being the integral function.
Arnaud
Edited: 16 Feb 2004, 9:03 a.m.
Posts: 1,841
Threads: 54
Joined: Jul 2005
Hi,
with the expression 'SIN(X)SQ(X1.5)1' on the data stack,
and assuming RAD mode, use the following program:
<< 'X' DUP2 0 ROOT 3 PICK 3 PICK 3 ROOT 4 ROLL 4 ROLL S >NUM >>
(where S is the integral symbol)
Essentially the same functionality as yours, but straightforward and somewhat shorter;)
Regards,
Raymond
▼
Posts: 362
Threads: 30
Joined: Jul 2005
I have never been very good at playing with the stack but essentially I believe all the solutions will be more or less the same.
What is important is the stack diagrams:
'equation' 'variable' guess ROOT
guess can be real or {low_limit high_limit}
and
low_limit high_limit 'equation' 'variable' S
I hope this helps you writting your own solution taking inspiration from the ones we proposed above. Good luck
Arnaud
▼
Posts: 1,792
Threads: 62
Joined: Jan 2005
Arnaud, Raymond 
Thank you very much for your responses. I'll run both your solutions on my 48G.
The crucial point, apparently, is to execute "S" (integration) with the stack preloaded, rather than as a function with input arguments inside parentheses. When I hit "S" inside a program, sometimes I got "S()", so I entered the arguments in a commaseparated list, as I'd done for another application. Then, the 48G didn't accept those arguments, singlequoted or not.
With all due respect, I believe that most users would find my 15C/34C program much more intuitive and comprehensible than these 48/49 solutions.
My objective was to see if and how this problem would be solved using RPL. In future, I might write an HP Forum article about using SOLVE/INTEG on RPN calcs. The RPL solutions would be treated separately, or mentioned in passing.
Regards,
 Karl S.
▼
Posts: 362
Threads: 30
Joined: Jul 2005
Quote: sometimes I got "S()"
I got this as well which might be a bug. In RPL you always put all the arguments first, which is why I prefer it to RPN as it is more consistent. Except for the loops and IF and CASE structures. Which is why I prefer sysRPL which is even more consistent.
Quote: With all due respect, I believe that most users would find my 15C/34C program much more intuitive and comprehensible than these 48/49 solutions.
Having never programmed in RPN before 1 or 2 years ago, the RPL is for me much more intuitive. I guess it is just a matter of knowing stack diagrams and being used to it... But I know that most people here, having more experience in RPN than RPL, will support your point of view.
Arnaud
Edited: 17 Feb 2004, 5:03 a.m.
Posts: 66
Threads: 9
Joined: Oct 2012
functions have parenthesis when you are in algebraic mode (when entering the expression inside single quotes).
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, Karl:
As I have no 48/49, just for the record, here's a solution for the HP71B/Math ROM. Assuming you have F(x) = f(x)g(x) defined elsewhere [e.g. 900 DEF FNF(X)=SIN(X)(X1.5)^2+1 ], this oneliner does the job:
10 DISP INTEGRAL(FNROOT(0,1,FNF(FVAR)),FNROOT(2,3,FNF(FVAR)),1E5,FNF(IVAR))
where INTEGRAL, FNROOT, FVAR and IVAR are Math ROM's keywords. Here, FNF(FVAR) stands for the function being "solved", FNF(IVAR) stands for the function being integrated, and 1E5 is the desired accuracy for the integral, which actually gives nearly 8 correct digits in this particular case.
Making sure that radians mode is set and running it, this will display your result (3.110575) in just 13 seconds. Your 15C version takes 110 seconds, which is rather good performance indeed.
Best regards from V.
▼
Posts: 362
Threads: 30
Joined: Jul 2005
Just for the record, on the 49g+ with FIX 6, I have 3.110575 in 3.93s and in standard mode 3.11057476957 in 6.0468s.
But I am still dreaming of buying myself a 15C.
Arnaud
Edited: 17 Feb 2004, 6:06 a.m.
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Arnaud wrote:
"Just for the record, on the 49g+ with FIX 6, I have 3.110575 in 3.93s"
That long ?! That's just 3.3 times faster than the HP71B !
After reading this forum and the newsgroups I was under the impression that the 49g+ was incredibly fast, thus *many* times faster than the very old HP71B Saturn CPU, which runs at 640 Khz (i.e.: 0.64 Mhz) if I'm not wrong.
What's the 49g+ CPU's speed ? 4 Mhz or more ? If so, I would expect it to be at least 4 ENTER .64 / (i.e: 6.25) times faster as a minimum, probably a lot more taking into account that RPL is supposed to be much more efficient than relativelyslow BASIC interpretation.
What gives !?
Best regards from V.
▼
Posts: 362
Threads: 30
Joined: Jul 2005
Here are a few times for FIX 6 or STD:
49g+: 3.93s and 6.07s
49G : 8.93s and 13.31s
48GX: 7.47s and 7.44s
The 49g+ emulates the saturn on a 75MHz ARM. The 49G and 48GX both have 4MHz saturns. You can see from these numbers why peopl find the 49g+ so much faster but also why they found the 49G so much slower at doing calculations and running programs.
Obviously the algorithm used is more important than the processor speed. However I am quite impressed by the results of the 71. Are you sure the Math ROM is all in BASIC?
Arnaud
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Arnaud posted:
"However I am quite impressed by the results of the 71. Are you sure the Math ROM is all in BASIC?"
No, no, I'm sorry if I didn't make myself crystal clear.
The whole Math ROM is written in Saturn's assembly language.
However, the ROM samples the userdefined function a *large* number of times in order to solve and/or integrate it, and that userdefined function is written in BASIC:
900 DEF FNF(X)=SIN(X)(X1.5)^2+1
so I'd say that the 71B is actually executing BASIC (your function definition and the 10 DISPLAY ... oneliner) most of the time.
And that's what amazes me ! Such a modern machine as the 49g+ with its 75 Mhz processor and efficient RPL should run its emulated Saturn code much faster than an old 0.64 Mhz physical Saturn CPU interpreting BASIC, shouldn't it ?
If not, numerically finding roots and/or computing integrals at a mere 3.3x speed advantage over a 20+ year old, slow CPU isn't exactly what I'd call an "incredibly fast" machine, is it ?
Best regards from V.
Posts: 1,792
Threads: 62
Joined: Jan 2005
Hello, Valentin (and Armaud) 
Thanks for the 71B routine. You may remember that I acquired a 71B a few months ago, but the Math ROM has proved elusive during my halfhearted searching. So, I can't try out your program at present.
I got the following results:
 113 seconds on my 1983 15C;
 9 seconds on a 49G using Arnaud's program;
 11 seconds total on a 48G with the same program (including 8 sec to get a display of integrals with roots as limits plus 3 seconds to evaluate the messy expression)
Arnaud's program can't even be run on a 28C because its integration accepts arguments in a different format (dummy variable and limits enclosed in a list), which I don't know how to automate. It also didn't accept valueloaded variable names for the limits.
Of course, the ensuing discussion of computational speeds and architecture is almost a moot issue to me. I would have had my answers to this straightforward, practical problem much faster with less mental effort on any of the RPN models I listed, due to the ease of conceiving and keystroking the program. In my hands, even the 34C would have left the 49G+ in the dust.
Regards,
 Karl S.
▼
Posts: 1,253
Threads: 117
Joined: Nov 2005
Ah, but that, Karl, is slightly unfair: you're comparing the user skill with the machine's specs.
Of course while money can buy you faster & better (?) machines, it takes effort and practice to become a wiser user...
So I'm with you 100%.
Best, ÁM
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, Karl:
Karl posted: "You may remember that I acquired a 71B a few months ago, but the Math ROM has proved
elusive during my halfhearted searching."
You should resort to a fullhearted searching, then. Trust me, having a 71B without its Math ROM is tantamount to capital sin, they belong together. The whole 71B operating system and CPU are optimized for math computations, and that potential is brought up to its full realization by having the Math ROM plugged in at all times. With it in place, there's no better numeric cruncher: incredible power AND extreme ease of use.
You can have much faster handheld hardware nowadays, but they won't include neither the extreme ease of programmability and use that BASIC affords, nor will many of them (PDAs and such) feature the incredibly powerful math algorithms that the 71B/MathROM does. Not to mention the fact that it's the one and only IEEE math fully compliant handheld computing device out there, to the best of my knowledge.
So, my heartfelt advice: get a Math ROM, *now* ! Myself, I own three, but then I've also got three HP71B to plug them in. :)
"I would have had my answers to this straightforward, practical problem much faster with less mental effort on any of the RPN models I listed, due to
the ease of conceiving and keystroking the program. In my hands, even the 34C would have left the 49G+ in the dust.
I trust your word, but then you'd surely agree that my oneliner for the 71B is absolutely straightforward: if you've had a look at it, it's essentially:
Area = Integral(Root(0,1,f(x)),Root(2,3,f(x)),precision, f(x))
Nothing, not even the quickest RPN program by the most skilled RPN programmer (such as yourself) could be faster or easier not to mention "intuitive", don't you agree ?
Best regards from V.
▼
Posts: 1,792
Threads: 62
Joined: Jan 2005
Hi, Valentin 
Yes, I understand and agree that my 71B should have a Math ROM, remembering the story you told about its development.
I have assembled a sizeable collection of HP calcs using two primary sources  eBay, and a local usedelectronics seller who appreciated HP calc's and bought them for resale. Two other models I bought new from retailers in 2002, as I did for my original 15C in 1983.
However, this method of acquisition hasn't worked well for obtainig a 71B Math ROM. I have yet to see a ROM offered on eBay as standalone or bundled with a trashed 71B, or on the MoHPC Classifieds. If I get impatient enough, there's always the "WTB" in MoHPC or other forum that will perhaps solicit an offer for topdollar purchase...
Best,
 Karl S.
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Karl posted:
"However, this method of acquisition hasn't worked well for obtainig a 71B Math ROM. I have yet to see a ROM offered on eBay as
standalone or bundled with a trashed 71B, or on the MoHPC Classifieds."
Seems to me that not many Math ROMs were directly sold to particulars, being as it was fairly expensive (I bought mine for something like US $200 back in the 80's) and
specialized. However, a lot of them were included as part of large corporative orders, i.e. several hundred HP71B + Math ROM + HPIL + 4K RAM were sold to a single corporation.
When said corporation obsoleted the product, the market was flooded with a large number of such machines, many of them absolutely new, unused (they were probably kept as spares). Many of them were acquired by some individual or small company to make them available in eBay. Surprisingly, bids didn't run very high at all, and I was able to get hold of several of them, at prices ranging from $65 to $90, and that included the 71B (ROM 1BBBB), original zip case, HPIL, Math ROM and 4K RAM, all of them new items, no box or manuals.
I quickly passed several to my HPfan friends, another to my daughter, and kept two for myself. It was a real bargain, and I wonder if such an offer keeps reappearing in eBay, as I suspect that the seller still has a lot more available for future auctions. I don't think he understood the machine's value, much less know anything about the 'desirability' of the pluggedin Math ROM bundled with it.
By the way, once you get the Math ROM, you'll quickly discover that it can be used for lots of purposes not directly related to math computations. For instance, I've used the fast matrix handling functions for games, such as
my chess MATER program for the 71B. It can be done without it, but would run much slower and be more clumsy.
Best of lucks and Best regards from V.
Posts: 362
Threads: 30
Joined: Jul 2005
My 48 just completely died so here are instructions for the 49.
As the 49 is a graphing calc I though we would solve the problem using these techniques:
RAD
LS+F4 NXT RESET Reset all
Highlight the EQ field
Start the EQW using the right key (different on G and g+)
Enter SIN(X)((X1.5)^21) ENTER
ERASE DRAW
move the cursor next to the first root FCN ROOT * (the multiply key) to select it NXT to bring the menu back
move the cursor to the next root ROOT NXT AREA and here you are
NXT SHADE to have a pretty picture
When you leave, you even have all you want on the stack!
What would be even better is if it was possible to Graph SIN(x) and (X1.5)^21 together and get the area between the curves in a same way. Actually SHADE will shade the area we want to know but AREA will only give for one curve not between the two.
This you can't do on a 15 or a 71 and is as easy to understand as the one liner of the 75.
Arnaud
