What's your favourite root finder?  Printable Version + HP Forums (https://archived.hpcalc.org/museumforum) + Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum1.html) + Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum2.html) + Thread: What's your favourite root finder? (/thread106400.html) 
What's your favourite root finder?  Les Wright  01222007 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 rootfinding. 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 sortof NewtonRaphson 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" 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
Re: What's your favourite root finder?  Karl Schneider  01232007 Hi, Les 
Quote: Well, I still prefer builtin machine code instead of addedon keystroke programs, so I'm going with the HP32SII implementation of SOLVE:
 KS
Re: What's your favourite root finder?  David Smith  01232007 A pig named "Sweetiepie".
Re: What's your favourite root finder?  Les  01242007 I knew pigs were smart, but that is really Some Pig.
Re: What's your favourite root finder?  Les Wright  01242007 Does Sweetiepie prefer NewtonRaphson, Brent, secant, Pegasus, or Illinois?
Les
Re: What's your favourite root finder?  Valentin Albillo  01252007 Hi, Les:
It will find and output all roots, real and/or complex, of any real polynomial of any degree whatsoever you may feed to it, without any input from the user at all (save the polynomial's coefficients, of course), at extremely fast speeds (Saturn's assembly language), and without ever failing.
It can deal with roots of high multiplicity, and with such exotic beasts as zero leading coefficients, infinities, denormalized values, and NaNs. No polynomial has ever been produced which makes PROOT fail, thus no need to "show interim results and show the path of convergence" in this case.
Find all roots of x^{5}3*x^{4}+8.1x^{2}1.37 = 0As for the general case, FNROOT, also in the HP71B's Math ROM, can solve just about anything quickly (assembly language again), and allows itself to appear in your function's definition, thus being capable of solving nonlinear systems of up to 5 unknowns. As for watching interim results or the path of convergence, just include the appropriate DISP or PRINT statements within your function's definition and there you are. You can even include some counter to let you know the number of iterations being performed. For example: Find a root of Cos(x) = x in [0,1], watching convergence: If insisting in user code, them I'm afraid I'm partial to ye olde couple of mine productions, namely the polynomial solver which can find all roots (real and/or complex) of a given polynomial (which can also have complex coefficients, which PROOT doesn't allow), written in HP41C user code and available in several userproduced ROMs (modified to take advantage of 41C Mcode complex words in the same ROM), and, for the general case, a very short but efficient and convenient routine I submitted for consideration to be included in the PPC ROM, also in HP41C user code. It's small, fast, quite general, can be called as a standalone, prompting program or as a nonprompting subroutine, and even let's the user specify both required precision and a limit for the number of iterations in case of no roots, aborting the procedure and passing the fact to the calling program. Best regards from V.
Edited: 25 Jan 2007, 9:54 a.m.
Re: What's your favourite root finder?  David Smith  01252007 Sweetiepie prefers truffels, but potatoes, carrots, and radishes will do. Hold the onions and garlic.
