There has been a lot of discussion in the Forum over the months about quadrature. Recently, I have turned my attention to the admittedly less glamourous topic of root-finding.

Even though I am aware of the sophisticated algorithms underlying the SOLVE functions in the HP41 Advantage Pac, HP34C, HP15C, HP42S, HP33S, etc, I must confess to really preferring elegant user code in a case like this, especially if I can manipulate it to show interim results and show the path of convergence.

Given this, the SV function from the PPC ROM is about my favourite right now. Only 32 steps, a straightforward implementation of the secant method (which has pretty good convergence for a wise initial guess), and the ability to show or print out interim results. The authors of the SV routine were apologetic about its simplicity and limitations, but I have no idea why. For its small size, it really does the job, and is an exemplar of the tight and economical coding that the PPC ROM was famous for.

I have played around with some others, like the Illinois modification of the regula falsi method in the HP Standard Applications Pac and the sort-of Newton-Raphson method in the HP11C owner's manual (I say "sort of" since the derivative is actually only numerically approximated rather than directly provided and computed), but SV is my favourite.

For anyone interested, here is the routine for HP41C/CV/CX. I have replaced the single synthetic step with corresponding user code:

01 LBL "SV"

02 STO 07

03 1

04 %

05 RCL Z

06 X=0?

07 X<>Y

08 STO 09

09 CLST

10 LBL 04

11 RCL Z

12 STO 08

13 RCL 07

14 FS? 10

15 VIEW X

16 XEQ IND 06

17 ST* 09

18 ST- 08

19 RCL 09

20 RCL 08

21 X#0?

22 /

23 STO 09

24 X<> 07

25 ST+ 07

26 RND

27 RCL 07

28 RND

29 X#Y?

30 GTO 04

31 RCL 07

32 END

You store the name of the function to be solved in register 6 (ASTO 06). Then, place on the stack the desired initial step size (or just 0 if you want to use the default of 1% of the initial guess) and the initial guess, then XEQ "SV". If you want to see interim or print results, set flag 10. Convergence is determined when the last two rounded results are equal so the setting of FIX, SCI, or ENG determines when the routine stops.

What's your favourite root finder?

Les