RPL calculators never had a simultaneous equation solver until the
MSLV function on the 49 series. Recently I got an HP28C and decided
to write one small enough to run on it. I wrote the code on the 48GX
and then keyed it in on the HP28C. The 28C has some annoying
limitations like no storage arithmetic or GET/PUT on local
variables.I changed to using stack storage rather than local variables.
Surprisingly, all those ROLL and PICK operations use less memory
than local variables even though the text is longer. The program
after some optimization is 346 bytes on my 48GX. On the HP28C I had
1274 bytes free after entering it. The 28C can solve useful systems
of nonlinear equations.The program is also useful on a 48G series machine or a 28S, and is
small and simple to use. It runs quite a bit faster on the 48GX than
on the 48GII, although the 48GII has a much faster editor.To enter the program on a 28C, bring up the STACK menu first,
because most of the keywords you will need are there. Make sure you
enter it correctly. You probably will not be able to edit it. You
may want to put a CLMF at the end so the display goes back to
normal. On a 48 this is not required.To use the solver:
Enter your expressions and save them in variables. They should be
expressions for which the calculator will find a zero. If you start
out with equations, put parens around both sides and change the = to
a  sign.Enter initial guesses and save them in the appropriate variables.
All the variables must exist, so the expressions will eval to
numbers.Enter four lines on the stack:
List of expressions to solve.
List of variables to solve for.
Acceptable error, indicating when to stop.
Delta (small number which is added to obtain slopes.)Run the solver. If you saved it as MSLV, enter MSLV CLMF
Example:
'2*X^3+Y+7*Z96' 'E1' STO
'3*X+6*Y^32*Z65' 'E2' STO
'6*X+4*Y+2*Z^342' 'E3' STO
1 'X' STO
2 'Y' STO
3 'Z' STO
{ 'E1' 'E2' 'E3' }
{ 'X' 'Y' 'Z' }
1E7
1E7
MSLV CLMFIn 4 FIX:
X=3.3161
Y=2.1666
Z=2.9857After the first iteration, you will see two lines. The first shows
the iteration count starting at 1. The second shows the worst
residual. The first line will count up and the second will hopefully
move toward zero.If the equations are illbehaved the program may generate an error.
Try a different set of initial guesses.The program evals each expression at the current guess and at guess
+ delta for each variable. It fills out a matrix of the slopes and a
vector of the values, uses the builtin linear algebra to solve the
linear system, subtracts the result from the guesses, and repeats
until the worst residual is less than the acceptable error.
%%HP: T(3)A(R)F(.);
\<< 4 PICK SIZE DUP
IDN DUP2 SWAP 1
\>LIST RDM 0 DUP
DO DROP 1 + 0 3
ROLL 1 6 PICK
FOR i 9 PICK i
GET DUP \>NUM 3 ROLL
i 1 \>LIST 3 PICK
PUT 3 ROLLD 1 8
PICK
FOR j 10 PICK
j GET 9 PICK DUP2
STO+ 8 ROLL i j 2
\>LIST 6 PICK \>NUM 6
PICK  12 PICK /
PUT 8 ROLLD STO
NEXT ABS 4
ROLL MAX 3 ROLLD
DROP
NEXT DUP 5 PICK
/ 1 7 PICK
FOR i 9 PICK i
GET OVER i 1 \>LIST
GET STO
NEXT DROP 3
ROLLD OVER 1 DISP
DUP 2 DISP
UNTIL DUP 8 PICK
<
END 9 ROLLD 8
DROPN
\>> END 
Multiple equation solver for the HP28C (program)

03202007, 03:24 PM
03202007, 04:49 PM
Quote: OT, is there any MES or SES for the 42S?
Edited: 20 Mar 2007, 4:52 p.m.
03202007, 05:34 PM
This is worth going to the Software Library. So far there's only one 28C/S program there. You might also consider submitting it to hpcalc.org.
Quote: This technique also makes for faster programs, as you may have noticed. I used it on this simple primefactorizer for the HP28C/S, which lacks it. I initially used global variables, then local variables and finally the stack only. The program is not fast because of the simple algorithm I used, but it would have been even slower otherwise. Since we're talking about equation solver, I'd like to present a linear equations system solver for the HP28S. It was written by one of my classmates back in 1987 and it was very useful in Circuit Analysis classes:
%%HP: T(3)A(D)F(.); Usage and examples in this old thread: http://www.hpmuseum.org/cgisys/cgiwrap/hpmuseum/archv015.cgi?read=82010 Unfortunately it doesn't work on the HP49/50G. One possible reason is TRN (transpose) behaves differently on the 28/48 and on the 49/50 calculators. Could anyone please point out other reasons? Regards, Gerson.
Edited: 22 Mar 2007, 7:24 a.m.
03212007, 02:32 PM
Multiple equation solver now down to 333.5 bytes  this is fun!
%%HP: T(3)A(R)F(.);
03242007, 03:10 AM
Quote:
Here's a quickanddirty port of Mike's program to the HP42S. It could use some work to give it a nice user interface  entering the vectors with the function and parameter names is pretty awkward right now. See the TEST program for how to initialize the parameters etc.; it's basically identical to Mike's RPL program.  Thomas
00 { 221Byte Prgm } Edited: 24 Mar 2007, 3:29 a.m.
03242007, 11:33 AM
Thanks! I will give this a try.
03242007, 01:48 PM
Thomas, this is great! You know, I am embarrassed to say that prior to this I didn't know that alphanumerics could be stored in matrices and vectors on the 42S. I thought you had real matrices and complex matrices, and that was it. Les
03242007, 05:01 PM
Thomas, for my own purposes I added SF 21 and VIEW "X", etc., to the test routine so I could either see or print the solution rather than search it out in my variable directory. Les
03242007, 09:01 PM
Printing the solution is a nice improvement, and there are a few others that come to mind: an easier way to enter the list of functions and parameters, and using a VARMENU to let the user set initial values...  Thomas 
« Next Oldest  Next Newest »
