From: jhmeyers@miu.edu (John H Meyers)
Newsgroups: comp.sys.hp48
Subject: Flexible Direct/Numeric SOLVE program (like HP18C/19B etc.)
Date: 7 Jun 1998 12:48:56 GMT
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Lines: 47
Message-ID: <6le27o$l27$1@news.iastate.edu>
Reply-To: jhmeyers@miu.edu
NNTP-Posting-Host: vax1.mum.edu
Xref: republic.btigate.com comp.sys.hp48:11651

The HP18C/19B calculators (and perhaps others) have a solver,
which looks just like the HP48 SOLVR environment (30 MENU);
however, these calculators first try to obtain a "direct"
solution (similar to using ISOL to solve the equation
algebraically for the desired variable), and the
numeric solver is utilized only if this fails.

We can do exactly the same on the HP48 using a small program;
below is a version which can be directly substituted for the
ROOT command, using exactly the same arguments.

Naturally, when a "direct" solution is possible,
any supplied guesses are ignored; if you would prefer not to
have to supply a "guess(es)" argument (as in the HP18C/19B,
which take optional initial guess[es] from any values
already stored in the variable being solved for),
then make the indicated change in the program.

With this program, roots for equations which can be solved
algebraically are found faster, and bad initial guesses
do not then prevent a solution from being found.

-----------------------------------------------------------
With best wishes from:   John H Meyers   <jhmeyers@mum.edu>
-----------------------------------------------------------

%%HP: T(3); @ SOLVE:  'algebraic' 'name' guess(es) ==> root

\<< OVER STO @ Omit if you don't want to require guess(es)

  @ Note that ISOL, ROOT, or ->NUM may fail for various reasons,
  @ leaving different arguments on the stack in each case, e.g.
  @ 'ABS(X)=0' 'X' ISOL ==> 'ABS(X)=0' 'X' [Unable to Isolate]
  @ 'EXP(X)=0' 'X' ISOL ==> 'X' 0 [LN Error: Infinite Result]
  @ This is why we "mark" the stack, and then drop error args.

  RCLF ROT ROT -55 CF @ "Mark" the stack position
  IFERR DUP2 ISOL     @ First try a "direct" solution
  THEN                @ Use numeric solver only if this fails
    WHILE 3 PICK TYPE 5 \=/ REPEAT DROP END @ Drop error args
    IFERR DUP RCL     @ Use existing value, if any, as guess
    THEN DROP 0       @ Else use zero and one as default guesses
    END ROOT          @ Root is both left on stack and stored
  ELSE ROT ROT DROP2  @ Drop saved args
    EQ\-> \->NUM DUP ROT STO @ "Direct" solution (after ISOL)
  END SWAP STOF
\>>