This program is Copyright © 1999 by Stefan Vorkoetter and is used here by permission.
This program is supplied without representation or warranty of any kind. Stefan Vorkoetter and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.
My HP-42S recently broke down, and I obtained a used HP-19C and HP-41CX from a colleague. After repairing the 19C, the first thing I missed (besides about 8k of memory) was the equation solving capability.
The HP-42S has a solver where you can provide a program for an equation of n variables, fix any n-1 of these variables, and solve for the remaining one. So, I immediately set out to write such a solver for my "new" 19C. After I repaired the 41CX, I ported the solver to that machine and enhanced it a bit to make it easier to use (alpha prompting and named equations).
The solver uses the secant method, in which the two most recent guesses are used to define a line. The point where the line intercepts the x-axis is used as the next guess. When two consecutive guesses are the same, the solution has been found. I'm sure this solver is not as good as the one in the HP-42S, but it works sufficiently well for my purposes. It can get into an infinite loop on periodic functions, line sin(x).
Using the solver is simple. First, rearrange your equation so all the terms are on one side. In other words, rewrite it in the form f(a1,...,an) = 0.
Next, enter the equation as a subroutine with an alphanumeric global label. The parameters are represented by the like-numbered registers (i.e. a1 is in register 01, and so on).
To solve for any one parameter,
After finding a solution, you can change parameters, and find further solutions for the same equation by pressing R/S and continuing with step 4 above.
See the sample problem for more details.
LINE CODE COMMENTS 01 LBL'SOLVE -main entry point 02 'FUNCTION? -prompt for equation to solve 03 AON 04 PROMPT 05 ASTO 13 06 AOFF 07 LBL 02 -prompt for register to solve for 08 RCL 00 -default is same as last time 09 'REGISTER? 10 PROMPT 11 STO 00 12 RCL 11 -prompt for first guess 13 'GUESS1? -default is answer from last solution 14 PROMPT 15 STO 11 16 STO IND 00 17 2 -prompt for second guess 18 * -default is twice the first guess 19 'GUESS2? 20 PROMPT 21 STO 12 22 XEQ IND 13 -compute f1 = f(R01,..,guess1,..,Rnn) 23 STO 10 24 RCL 12 -compute f2 = f(R01,..,guess2,..,Rnn) 25 STO IND 00 26 LBL 01 27 XEQ IND 13 28 STO 12 -compute guess2 <- (guess1 f2 - guess2 f1) / (f2 - f1) 29 RCL 11 30 * 31 RCL IND 00 32 STO 11 -move old guess2 to guess1 while we're here 33 RCL 10 34 * 35 - 36 RCL 12 37 ENTER^ 38 X<> 10 -move old f2 to f1 while we're here 39 - 40 / 41 STO IND 00 -save new value for guess2 42 RCL 11 -compare to previous guess 43 X!=Y? -keep going until they're the same 44 GTO 01 45 RTN 46 GTO 02 -if user press R/S, go back to solve same eqn again 47 END
R00 | Index i of variable to solve for |
R01..R09 | Variables to solve for (up to 9) |
R10 | Previous value for f(R1,..,Rn) |
R11 | Previous value of Ri |
R12 | Second guess during initialization. Current value for f(R1,..,Rn) during main loop |
R13 | Alpha name of function to solve for. |
The net resistance, r3, of two parallel resistors of resistance r1 and r2 is given by:
r3 | = | r1 r2 |
------------- | ||
r1 + r2 |
This can be rewritten in the form f(r1,r2,r3) = 0 as follows:
r1 r2 | - | r3 | = | 0 |
------------- | ||||
r1 + r2 |
The following subroutine implements this equation:
LINE CODE 01 LBL'RES 02 RCL 01 03 RCL 02 04 * 05 RCL 01 06 RCL 02 07 + 08 / 09 RCL 03 10 - 11 RTN 12 END
What is the resistance of a 5k Ohm and 10k Ohm resistor in parallel?:
KEYSTROKES | DISPLAY | COMMENTS |
5 STO 01 | 5.0000 | Store 5 in R01 |
10 STO 02 | 10.0000 | Store 10 in R02 |
XEQ "SOLVE" | FUNCTION? | Run the solver |
"RES" R/S | REGISTER? | Solve equation "RES" (calculator will already be in ALPHA mode) |
3 R/S | GUESS1? | Solve for R03 |
3 R/S | GUESS2? | First guess is 3 |
4 R/S | 3.3333 | Second guess is 4. Answer is 3.3333 |
The answer is 3.3333k Ohms.
What resistance is needed in parallel with a 10k Ohm resistor to give a 2k
Ohm parallel resistance?:
KEYSTROKES | DISPLAY | COMMENTS |
2 STO 03 | 2.0000 | Store 2 in R03 (R02 is still 10 from the previous problem) |
R/S | REGISTER? | Solve the same equation again |
1 R/S | GUESS1? | Solve for R01 |
R/S | GUESS2? | First guess is 3.3333 (answer from last time) |
R/S | 2.5000 | Second guess is 6.6667 (twice first guess). Answer is 2.5 |
The answer is 2.5k Ohms.
If the program cannot find a solution, it will eventually end up dividing
by zero, which will display DATA ERROR. For example, what resistance
is needed in parallel with a 10k Ohm resistor to give a 12k Ohm parallel
resistance?:
KEYSTROKES | DISPLAY | COMMENTS |
12 STO 03 | 12.0000 | Store 2 in R03 (R02 is still 10 from the previous problem) |
R/S | REGISTER? | Solve the same equation again |
1 R/S | GUESS1? | Solve for R01 |
R/S | GUESS2? | First guess is 2.5 (answer from last time) |
R/S | DATA ERROR | Second guess is 5 (twice first guess). Can't find solution. |
It's not possible to put something in parallel with a 10k Ohm resistor and end up with a higher resistance.
This program started life on my HP-19C. The listing of the HP-19C version gives notes on portability. As shown here, the program will work on any of the HP-41 models (C, CV, and CX). It will probably also work on the HP-42S, but that would be redundant since the 42S has a solver built in.
If you want to use the solver as a subroutine from within another program, you'll need to modify the front end a bit to get rid of the prompting. You'll probably want something more along the lines of the HP-19C version, which takes the register number to solve for, and the two initial guesses, on the stack. You can enhance this to take the name of the equation in the alpha register.
The solver as written is 99 bytes long, and will fit on one track of a magnetic card if you happen to have a card reader.
Go back to the HP-41 software library
Go back to the general software library
Go
back to the main exhibit hall