▼
Posts: 1,545
Threads: 168
Joined: Jul 2005
Ok, so I started trying the examples from the IG routine in the PPC rom manual using the builtin integration function on the 34s.
Less than nice results. :) Of course, this was expected.
So, I then decided...why not just adapt the PPC ROM IG routine and key it into the 34s.
Everything keyed properly with a couple of exceptions. The HP 41 puts numbers on one program line while the 34s puts each digit on a separate line. Not usually a problem even though not as readable as the HP 41 way.
However, it did cause a problem until I spotted it in the IG listing.
Lines 17 and 18 in IG are E and then 2, which enters a 1 and then a 2 into Y and X, respectively.
My first attempt was to key a 1 then ENTER and a 2 and go back and delete the ENTER. Oops. That made the 1 2 a 12. So, if you have things like 1 and 2 to be entered as two numbers, the ENTER is needed. No hidden "null" like on the HP 41 series.
That said, IG runs like a charm with one change (Ok, some other changes too like RCL L for LastX, but those are not real changes):
IG looked for alpha labels for the function to be integrated. I found that XEQ ind 10 with a 3 letter alpha label inside errored out...so I changed the program to simply XEQ 99 and used label 99 for the function.
It is very fast, but even the 34s is taking its time right now solving the integral from 0 to 1 of x^(1/2). The "Answer" is 2. So far, after about 45 minutes, the 34s has 1.9999678... and it is still going. Of course, I put it in SCI 9, so I am being a real pain to the poor 34s.
The program IG on the 34s takes 93 program steps/lines. If you want to do numerical integration, that is probably worth it.
I plan to show the results from the IG program and the builtin integration command when I can.
Hey 34s team... those "internal" constants in the manual for the 34s integration... do they take up more/less space than a 93 step program? Or is it that the constants are not in a similar memory location than an IG programlike function would be?
Edited: 13 June 2011, 4:52 p.m.
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
Quote: IG looked for alpha labels for the function to be integrated. I found that XEQ ind 10 with a 3 letter alpha label inside errored out...so I changed the program to simply XEQ 99 and used label 99 for the function.
We cannot distinguish alpha data from numbers at the moment. There are two commands [alpha]XEQ and XEQ[alpha] that do what you want and more. The internal command has a special call user routine function available that can call alpha or numeric labels.
Quote: Hey 34s team... those "internal" constants in the manual for the 34s integration... do they take up more/less space than a 93 step program? Or is it that the constants are not in a similar memory location than an IG programlike function would be?
93 steps is 186 bytes. The constants take eight bytes each so 208 bytes for the magic constants. The integration program isn't small either  see xrom.c. I doubt 93 steps is enough once you have to start dealing with the user's code returning NaN's and infinite results and such but it wouldn't be a huge amount more.
However, the big limitation is the internal integration command is capped at five persistent registers (i.e. there are only five registers that will survive execution of the user's routine). It don't have any more scratch registers beyond the four level stack but more could be made available at a pinch  they wouldn't survive the user's code being executed however.
If you code meets the register requirement, please send it to me and I'll replace the internal integration routine. Actually, send it anyway and it can go into the library :)
 Pauli
▼
Posts: 1,545
Threads: 168
Joined: Jul 2005
Hey Pauli.
It is simply the IG routine from the PPC ROM manual. Surely you have that? :)
Actually, check ur mail since I am sending you the PPC ROM program listing.
And, note that this program as written WILL use user memory registers. Quite a few of them.
So, to have this "in rom" will mean that it will use memory registers.
Edited: 13 June 2011, 6:41 p.m.
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
Thanks, file received. I don't have a PPC manual although I do have a module. I think it is on the DVDs though.
I really don't want internal commands touching user's registers unless there is a specific and well defined purpose that cannot be abused. This isn't the case here unfortunately.
 Pauli
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
How many registers are used? Any of them just constants stored for convenience in registers? Any of them only used internally between executions of user code and can be lost if the user code program contains a STOP (which will kill RAM)?
If it really will not fit nicely within the internal (X)ROM constraints, we can still create a "default library" which gets it. The default library can then be made available with the flash download so that it is automatically included when flashing the calc. It will occupy one of the PSTO slots, of course.
Pauli, Walter, what do you think?
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
Not a chance of it fitting in XROM space. Way too many registers used.
A default library is a decent idea.
 Pauli
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
Pauli,
I've high hopes of your typing skills. If you provide a library file (either salvaged from the calculator via SAMBA or created on the emulator) I'll take care of its inclusion in the default build. We can put all the stuff in the "library" folder in it.
Anybody else willing to provide useful programs for a default library?
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
Most of the stuff in the library folder shouldn't be included. Much of it is a copy of the xrom code of the same function. I.e. useful for explaining how the internals work and how some of the special commands are used but that is all.
 Pauli
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
I agree, but e.g. the n queens benchmark or the code breaker game are likely candidates as is the improved integrator.
We need some input from the community.
▼
Posts: 875
Threads: 37
Joined: Jul 2005
Here is a new version of the code breaker game that works with the latest versions of wp34s. Also includes a couple of prompts and/or messages that were not in the earlier version.
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
Thanks Jeff! I leave it to Pauli to integrate it into the package.
Posts: 1,545
Threads: 168
Joined: Jul 2005
Below are the results from comparing the WP 34s builtin integration function vs. the PPC ROM converted IG routine.
PPC ROM
IG Routine WP 34s WP 34s
Example Function Builtin IG Program value
1 0 to 1: 4/(x^2+1) 3.141593 3.141593
2 0 to 1: x^(1/2) 0.666671 0.666667
3 0 to 1: Sin(PI*X) 0.636620 0.636620
4 0 to 1: LN(x) 0.999147 1.000000
6 0 to 2: (x(4x))^(1/2) 3.141620 3.151593
8 0 to 1: COS( LN(x)) 0.501097 0.500000
9 0 to 1: x^(1/2) 1.967500 2.000000
10 0 to 1: (1  x^2)^(1/2) 0.785405 0.785398
12 1 to 1: ((1x^2)(2x))^(1/2) 2.203398 2.203346
The tests were fairly maddening. The 34s integrator gets its results very quickly, but sometimes is just off enough to irritate you. :) The IG program takes longer most of the time but gets more "accurate" values.
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
The wp34s integrator uses a fixed number of points and does not iterate. It should be fairly easy to create a subinterval algorithm that divides the integration interval in two halves and integrates each part with the built in command. This can be redone several times until the combined results do not change any more.
▼
Posts: 1,545
Threads: 168
Joined: Jul 2005
Well, the 34s integrator did a good job in many circumstances, but things like the quick result of 0.501097 to the COS(LN(X)) integral were disappointing as was the 1.9675 result to the SQRT(X) integral.
the next task I plan to try is a matrix series modeled after the M1  M5 routines from the PPC ROM and the RRM application program from the PPC ROM.
Now THAT would make a good standard library program, IMO.
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
I was thinking JMB's matrix library would be well suited for this.
 Pauli
▼
Posts: 1,545
Threads: 168
Joined: Jul 2005
Ah, but given my slim programming skills :) it is much more likely that I can rewrite the PPC ROM routines to the 34s. Now if JMB or someone else can rewrite the Matrix library... Ha!
Seriously, matrix functions are "the" missing piece to the 34s, as it is now...as the developers know well. A library that can do systems of equations, determinants (of course to do the systems) and inverses would be a great thing to fill that gap.
Posts: 3,229
Threads: 42
Joined: Jul 2006
Any idea what the error estimates returned by the 34s's integrator are?
 Pauli
▼
Posts: 1,545
Threads: 168
Joined: Jul 2005
Well, for the COS(LN(X)) integral, the Y stack level contains 0.002169.
Should have written down the others. :)
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
The answer + or  the error estimate brackets the true integral nicely in this case at least.
What's needing is a wrapper that uses the built in integrator and subdivides the interval until the sum of the error estimates is small enough.
 Pauli
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
...right now solving the integral from 0 to 1 of x^(1/2). The "Answer" is 2. So far, after about 45 minutes, the 34s has 1.9999678...
Hi,
I'm wondering how the WP34S (and also the PPCROM) can calculate this numeric integral at all, when the integrand x^(1/2) is not defined at the left endpoint x=0?
Is there any code in the integration routine which checks for such 'undefined' function values, or is this integration algorithm just using function values at some midpoints of the subintervals?
Can these algorithms for numeric integration (used in the WP34S and PPCROM) be found anywhere?
Franz
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
The 34s's integration code doesn't evaluate at the end points.
It uses a 10/21 point GaussKronrod quadrature.
The freely available source code (in xrom.c) implements the algorithm.
More information can be found on the Internet by visiting your friendly search engine.
 Pauli
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
The 34s's integration code doesn't evaluate at the end points.
Well, that's good for such improper integrals! ;)
Thanks for the info, I know a few integration methods but GaussKronrod was new to me.
Franz
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
GaussKronrod quadratures are pretty much the standard these days. Their main benefit is that the function is evaluated for the Kronrod quadrature and the Gauss points are a subset. Thus you get two different order estimates of the integral which gives you an idea of the error.
Generally they are used with a fairly adaptive wrapper that increases the number of quadrature points  this can be done while reusing the existing function evaluations if the points are carefully chosen. The 34s isn't this sophicated however.
Quite an interesting lump of theory :)
 Pauli
Posts: 1,545
Threads: 168
Joined: Jul 2005
Here is the PPC ROM IG routine writeup:
PPC ROM IG Routine
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
Here is the PPC ROM IG routine writeup:
PPC ROM IG Routine
Thanks, very interesting and detailled article! :)
Of course Romberg is one of the standard methods, but so far I didn't know that it could also be used for improper integrals.
Franz
