Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Flexible Direct/Numeric SOLVE program (like HP18C/19B etc.)

6 views
Skip to first unread message

John H Meyers

unread,
Jun 7, 1998, 3:00:00 AM6/7/98
to

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 <jhme...@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
\>>

0 new messages