IntroductionUnlike many advanced calculators, the hp 39g+ has no built-in solver for simultaneous equations. It does have the necessary matrix manipulation commands but you need to remember exactly how to use them and how to interpret the results. This program automates the process and provides prompts and information about the solutions. |
ExampleConsider the set of three simultaneous equations below: Where x,y and z are the 'unknowns' whose values are to be found. Here the first three columns are the coefficients, including the signs, of the unknowns x,y,z and the fourth column is the total on the right hand side of each equation. Converting this matrix to 'reduced row echelon form' gives the result: Converting a matrix to reduced row echelon form by hand is tedious, but luckily the hp 39g+ contains a built-in command to do this. |
Loading SimulSolveCopy the files SIMULSOL.000, HP39DIR.000 and HP39DIR.CUR to an empty directory on a PC, start the HP39G Connectivity program and point it to the directory holding the three files. |
Running SimulSolveRun SimulSolve from the PROGRAM catalogue or the HOME screen.
The following screen is now shown as a reminder of how to enter the coefficients:
(The display is 'frozen' at this point; press any key to continue.) After pressing a key the Matrix Editor is displayed for matrix M1.
The number of rows and columns in M1 depends on the number of unknowns chosen.
When all the coefficients have been entered press Softkey 6 (OK) to continue. Note that you should not delete any rows or columns from M1; If there are N unknowns then M1 must have N rows and N+1 columns filled in.
This tells you that the system of equations could indeed be solved and that the values of the unknowns are now stored in matrix M2, with the first unknown in M2(1), the second unknown in M2(2), etc. After a few seconds the display changes to the Matrix Editor but this time showing M2 so that the answers can be viewed:
Pressing Softkey 6 (OK) returns to the PROGRAM catalogue or the HOME screen, but the solutions remain in M2. The original coefficient matrix is still in M1. |
Error MessagesWhen prompted for the number of unknowns, entering zero or a negative number produces the error message Minimum is 1, and the prompt is repeated. (The program will accept a system of one equation with one unknown, even though the solution is trivial.) If the message Insufficient Memory - Edit program? appears, either after choosing the number of unknowns or after entering the coefficients, then the calculator does not have enough free memory to create the matrices. If any rows or columns were deleted from M1 while entering the coefficients then the message Bad Argument Value - Edit program? appears after pressing OK. It is possible for the system of equations to be inconsistent, that is they contradict themselves. A simple example would be: Here the last two equations have the same coefficients of x,y,z but a different total, which is clearly nonsensical. Sometimes it is not so obvious that the equations are inconsistent but if they are then there are no solutions. In this situation SimulSolve shows:
The display pauses at this point, and pressing a key returns to the screen from which the program was called. There will be nothing meaningful in M2 so it is not displayed. A second possibility is that the equations are not all independent. The equations being independent means that none of them can be obtained just by adding together other equations, or multiplying one by a factor. An example of non-independent equations is:
Again the display pauses at this point, and pressing a key returns to the screen from which the program was called. The contents of M2 will not be particularly useful so it is not displayed. |
Hardware RequirementsSimulSolve runs on a Hewlett-Packard 39g+ calculator. It should also work on the 39g and 40g, and possibly the 38g, but has not been tested. The program takes up 0.9 kilobytes of RAM when first loaded, which expands to 2.5 kilobytes when run. The maximum number of unknowns that can be solved for is limited by the amount of free memory. For the hp 39g+ with most of its memory free this limit is about 80 unknowns. (Which would be very time-consuming to enter since there would be 6480 numbers to type in.) |
Variables UsedSimulSolve uses the following HOME variables, and will therefore overwrite any existing information stored in them:
|
SpeedSystems of 3 or 4 equations are solved almost instantly. 10 equations take about 4 seconds and 20 equations take 25 seconds. 50 equations take around 7 minutes to solve. |
Program Listing01) INT(ÖÕLIST(SIZE(M1)))®S: 02) DO 03) INPUT U;"Simultaneous Equations"; 04) "Unknowns:";"How many unknowns?";U: 05) INT(U)®U: 06) IF U<1 THEN MSGBOX "Minimum is 1":END: 07) UNTIL U>0 END: 08) IF U¹S THEN 09) MAKEMAT(0,U,U+1)®M1: 10) ELSE REDIM M1;{U,U+1}:END: 11) ERASE: 12) DISP 1;"Enter coeffs. c of": 13) DISP 3;"c1X+c2Y+c3Z+...=d1": 14) DISP 5;"into M1 columns 1-"U: 15) DISP 6;"and d into column "U+1: 16) FREEZE: 17) EDITMAT M1: 18) ERASE: 19) SUB M1;M1;{1,1};{U,U+1}: 20) RREF(M1)®M2: 21) 0®S: 22) FOR I=1 TO U; 23) S+M2(U,1)®S: 24) DELCOL M2;1: 25) END: 26) IF S==0 THEN 27) BEEP 300;.3:BEEP 200;.8: 28) DISP 1;"** Problem **": 29) IF M2(U,1)==0 THEN 30) DISP 3;"Equations not": 31) DISP 4;"independent.": 32) DISP 5;"Infinitely many": 33) DISP 6;"solutions.": 34) ELSE 35) DISP 3;"Equations inconsistent": 36) DISP 4;"No solutions.": 37) END: 38) FREEZE: 39) ELSE 40) BEEP 900;.2:BEEP 700;.3: 41) DISP 3;"Equations have unique": 42) DISP 4;"solution.": 43) DISP 6;"X,Y,Z... in M2(1.."U")": 44) WAIT 4: 45) EDITMAT M2: 46) END: Note: ® means 'STO' The line numbers are just for convenience and not part of the program. |
Comments01) Initial number of unknowns based on current size of M1. 03) Show prompt and get the number of 04) unknowns. 05) U must be an integer >= 1 06) Show error box if not and 07) repeat prompt. 08) If number of unknowns has changed then 09) create a new blank matrix, 10) else ensure matrix is correct size. 11) Clear the display. 12) Display a reminder of how to enter 13) the coefficients into M1. 14) 15) 16) Pause until a key is pressed. 17) Call Matrix Editor for M1. 18) Clear the display. 19) Ensure M1 is still the same size. 20) Obtain the solution in M2. 21) Zero solved? counter. 22) Go through each column of M2. 23) Count ones in last row of M2. 24) Delete all but last column of M2. 25) 26) If there were no ones in last row 27) then equations could not be solved. 28) Show error message. 29) If last 'solution' came out as 30) zero then the equations are not 31) independent so show suitable 32) error message. 33) 34) If last 'solution' was not zero 35) then equations are inconsistent. 36) Report this. 37) 38) Pause while message is read. 39) If last row was not all zeroes 40) then equations have a unique 41) solution. 42) Report this, and also where 43) results are stored. 44) Let user view message then 45) show solutions in matrix editor. 46) End of program. |
Program written by Peter Ochocki, December 2005.