The Museum of HP Calculators


Equation Solver for the HP-19C/HP-29C

This program is Copyright © 1998 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.

Overview

My HP-42S recently broke down, and I obtained a used HP-19C from a colleague. After repairing it, 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.

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, like sin(x).

Usage

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 label 9. The parameters are represented by the like-numbered registers (i.e. a1 is in register 1, and so on).

To solve for any one parameter, store values for all the other parameters in the appropriate registers, enter two initial guesses for the parameter you wish to solve for, enter the parameter number, and press GSB 0.

See the sample problem for more details.

The Program

LINE     KEYSTROKES    COMMENTS

 01      g LBL 0      main entry point
 02      STO 0        store index of variable to solve for
 03      R↓
 04      STO .2       store second guess
 05      R↓
 06      STO .1       store first guess
 07      STO i        f1 = f(R1,..,Ri1,..,Rn)
 08      GSB 9
 09      STO .0
 10      RCL .2       f2 = f(R1,..,Ri2,..,Rn)
 11      STO i
 12      g LBL 1
 13      GSB 9
 14      STO .2
 15      RCL .1       Ri2 ← (Ri1 f2 - Ri2 f1) / (f2 - f1) 
 16      ×
 17      RCL i 
 18      STO .1       move old Ri2 to Ri1 while we're here
 19      RCL .0
 20      ×
 21      -
 22      RCL .0
 23      RCL .2
 24      STO .0       move old f2 to f1 while we're here 
 25      x⇔y
 26      - 
 27      ÷ 
 28      STO i        save new value for Ri2 
 29      RCL .1       compare to previous guess 
 30      f x≠y        keep going until they're the same
 31      GTO 1
 32      g RTN

Registers

R0 Index i of variable to solve for
R1..R9 Variables to solve for (up to 9)
R.0 Previous value for f(R1,..,Rn)
R.1 Previous value of Ri
R.2 Second guess during initialization. Current value for f(R1,..,Rn) during main loop

Sample Problem

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     KEYSTROKES    COMMENTS

 33      g LBL 9       solver uses subroutine with label 9
 34      RCL 1
 35      RCL 2
 36      ×
 37      RCL 1
 38      RCL 2
 39      +
 40      ÷
 41      RCL 3
 42      -
 43      g RTN

What is the resistance of a 5k Ohm and 10k Ohm resistor in parallel?:

KEYSTROKES DISPLAY COMMENTS
5 STO 1 5.0000 Store 5 in R1
10 STO 2 10.0000 Store 10 in R2
3 ENTER↑ 3.0000 First guess is 3
4 ENTER↑ 4.0000 Second guess is 4
3 GSB 0 3.3333 Solve for R3

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 3 2.0000 Store 2 in R3 (R2 is still 10 from the previous problem)
3 ENTER↑ 3.0000 First guess is 3
4 ENTER↑ 4.0000 Second guess is 4
1 GSB 0 2.5000 Solve for R1

The answer is 2.5k Ohms. If the program cannot find a solution, it will eventually end up dividing by zero, which will display 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 3 2.0000 Store 2 in R3 (R2 is still 10 from the previous problem)
3 ENTER↑ 3.0000 First guess is 3
4 ENTER↑ 4.0000 Second guess is 4
1 GSB 0 Error Solve for R1

It's not possible to put something in parallel with a 10k Ohm resistor and end up with a higher resistance.

Portability to Other HP Calculators

This program should be fairly easy to make work on other HP calculators that have indirect addressing. You may have to change some of the register usage (most of the other models don't have the .n registers). You'll also need to change the indirect addressing. The HP-19C/29C use R0 as the indirect register. Some models have a specific i register, so you'll have to make the following changes:

 STO i     →  STO (i)
 RCL i     →  RCL (i)
 STO 0     →  STO I

Later models, such as the HP-41C can use any register for indirection, so the changes would be:

 STO i     →  STO IND 0
 RCL i     →  RCL IND 0

GTO Go back to the software library
GTO Go back to the main exhibit hall