The Museum of HP Calculators

HP Forum Archive 20

[ Return to Index | Top of Index ]

WP34S: An integration wrapper
Message #1 Posted by Miguel Toro on 9 Oct 2011, 10:55 p.m.

Another week-end little project.

As suggested by the WP34s team on a older post, I tried to make a wrapper to improve accuracy for the integration function.

A test with sqrt(abs(x-1)), from 0 to 2, gives:

WP 34s : 1.30929962
WP 34s with the wrapper (fix 5) : 1.33333672

Expected : 4/3

Using this program:

LBL 10 1 - ABS [sqrt] RTN

Any comment to improve it as always very welcome.

Miguel

Edited: 9 Oct 2011, 11:04 p.m.

      
Re: WP34S: An integration wrapper
Message #2 Posted by gene wright on 9 Oct 2011, 11:10 p.m.,
in response to message #1 by Miguel Toro

Hi Miguel!

Try it on these expressions from the PPC ROM examples:

Dropbox link to IG results

            
Re: WP34S: An integration wrapper
Message #3 Posted by Miguel Toro on 10 Oct 2011, 7:21 a.m.,
in response to message #2 by gene wright

Hi Gene,

Here are the results. Not so bad, I think. Function 10, takes too long, so I ran it with FIX 3. Against my own advice, the others where done with FIX 6, getting decent running times.

1:	3.141593
2:	0.666667
3:	0.636620
4:	-0.999984
6:	3.141594
8:	0.499995
9:	1.991321
10: 	0.785399	FIX 3 (too slow otherwise)
12:	2.203347

      
Re: WP34S: An integration wrapper
Message #4 Posted by Paul Dale on 9 Oct 2011, 11:22 p.m.,
in response to message #1 by Miguel Toro

Nice compact routine.

- Pauli

      
Re: WP34S: An integration wrapper
Message #5 Posted by Marcus von Cube, Germany on 10 Oct 2011, 2:36 a.m.,
in response to message #1 by Miguel Toro

A few minor remarks:

In your instructions, "cumulatif" should spelled "cumulative". (Neither of us is a native speaker, I assume, so we need to help each other. :-))

Why do you set the stack size to 4? I haven't checked your code but if you don't need A to D for other purposes or rely on the duplication of T just leave the setting alone. If you really need it, use STOM/RCLM to save and restore the mode.

The iteration uses the approximate comparison operator which relies on the display setting (Am I right, Pauli?). Just put a comment in that explains how this affects accuracy of the integral.

I'd like to see some // comments at the end of the lines. This would help to understand your code and it will not disturb the assembler.

Edited: 10 Oct 2011, 2:39 a.m.

            
Re: WP34S: An integration wrapper
Message #6 Posted by Walter B on 10 Oct 2011, 2:40 a.m.,
in response to message #5 by Marcus von Cube, Germany

Quote:
The iteration uses the approximate comparison operator which relies on the display setting (I'm I right, Pauli?).
Please see page 58/102. You are :-)
            
Re: WP34S: An integration wrapper
Message #7 Posted by Miguel Toro on 10 Oct 2011, 6:54 a.m.,
in response to message #5 by Marcus von Cube, Germany

Got it! I will do the changes.

Thanks,

Miguel

Done!

Note: The possibility of using complex instruction makes the code more compact, so i need a four register stack to take advantage of that, so I followed your advice and stored and restored modes.

Edited: 10 Oct 2011, 8:23 a.m.

                  
Re: WP34S: An integration wrapper
Message #8 Posted by Marcus von Cube, Germany on 10 Oct 2011, 8:38 a.m.,
in response to message #7 by Miguel Toro

Quote:
so i need a four register stack to take advantage of that
Only if you rely on the duplication of z/t when doing a complex drop or an operation that drops the stack.

The way it is now it works and that's fine. You should note in the instructions that J is used for saving the mode.

Maybe a limit should be set on the number of iterations. Do you do the halving of intervals over the complete range over and over or do you have a check for each subinterval and divide only if a subinterval is outside the accuracy bounds? The latter would probably need some kind of backtracking which is obviously not possible without recursive programming.

                        
Re: WP34S: An integration wrapper
Message #9 Posted by Miguel Toro on 10 Oct 2011, 8:49 a.m.,
in response to message #8 by Marcus von Cube, Germany

Yes. I will think about setting a limit on the number of iteration.

Thank you Marcus,

Miguel

                              
Re: WP34S: An integration wrapper
Message #10 Posted by Paul Dale on 10 Oct 2011, 4:57 p.m.,
in response to message #9 by Miguel Toro

An iteration limit would be a good idea. I tried integrating LN(x) from 0 to 1 and gave up after my laptop had been crunching away for over half an hour. I was using ALL mode sound rounding was to 12 digits not a fixed number of decimals.

- Pauli

                                    
Re: WP34S: An integration wrapper
Message #11 Posted by Miguel Toro on 10 Oct 2011, 9:59 p.m.,
in response to message #10 by Paul Dale

With an iteration limit of 15, LN gives -0.999973 in six seconds. I will leave this limit in the routine.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall