|
|
|
|
The HP 35s programmable calculator.
|
A Matrix Multi-Tool for the HP 35s Programmable Calculator
This is my second attempt at a large program for the new
HP 35s programmable scientific calculator from
Hewlett-Packard. My previous program
addressed the curve fitting shortcomings
of the 35s (compared to the HP-41C/CV/CX with Advantage Pac, or the HP-42S).
This program is a start at doing the same for matrix functionality.
The HP-15C was the first calculator to introduce comprehensive support for
matrix operations. HP quickly added equivalent functionality to the 41C series
with the Advantage Pac, and the 42S came with these operations built in as
well. The HP 35s does not have any general purpose matrix operations built
in, although it can solve 2x2 and 3x3 linear systems.
The program I present here is a long way from being as powerful as the
facilities provided by the 15C, 41C/Advantage, or 42S, but it does provide
several useful matrix operations in one simple tool. It is loosely modelled
after the Advantage Pac matrix program, which provides an easy-to-use
subset of the functionality of the matrix library.
What it Does
Given an N×N matrix A, and an
N-element vector b, the matrix multi-tool will do the
following:
-
Compute A-1, the inverse of A.
-
Compute the determinant of A.
-
Solve the system of linear equations, Ax=b, giving
column vector x.
-
Quickly solve additional Ax=b systems for different
b vectors.
-
Perform matrix-vector multiplication of A and b.
The matrix multi-tool uses Gaussian elimination with partial pivoting to
intially compute A-1 and simultaneously solve
Ax=b. The determinant is also computed during this
operation. The inverse is left in A, and x is left in
b. When solving additional systems of equations for the same
A and different b vectors, the program evaluates
A-1b to yield x.
If you're only interested in A-1 and/or A's
determinant, you can omit entering values for b and ignore the
solution of x.
You can also use the built-in matrix-vector multiplication routine directly
if you just want to multiply a matrix by one or more vectors.
Thanks to the HP 35s' support for complex numbers, the matrix multi-tool
works with complex matrices too.
Using the Program
Before running the matrix multi-tool, make sure flag zero is clear by pressing
FLAGS CF 0 (the program doesn't clear this flag
itself because it is used to maintain information between invocations).
Start the program by pressing XEQ M ENTER. This will display the
main menu, which looks like this:
The menu choices are:
-
Go to dimension/edit/view menu for matrix A.
-
Go to edit/view menu for column vector b.
-
Compute inverse and determinant of A, and solve Ax=b for x.
-
Unsolve, restoring original A and most recent b.
-
Multiply matrix A by vector b.
Pressing R/S without selecting a choice exits the matrix program
(this is important, to ensure flag 10 is cleared so equations will work in
other programs).
Entering Matrix A
Press 1 R/S from the main menu to display the matrix A
menu:
The menu choices are:
-
Specify the dimension N for N×N matrix A and N-vector b.
-
Edit the entries in matrix A.
-
View the entries in A.
Pressing R/S without selecting a choice will return you to the
main menu.
Specifying the Matrix Dimension
Press 1 R/S to specify the dimensions of
N×N matrix A, and consequently
N-vector b. The program will display:
The currently specified dimension is displayed. Enter the desired dimension
and press R/S (or just press R/S to keep the
existing dimension). The lowest allowed dimension is 2 and the highest
depends on the amount of free memory. If the matrix multi-tool program is
the only one in memory, you can work with a matrix of dimension up to
19×19.
If you enter a dimension that is too small, the program will display
N TO SMALL. Pressing R/S will return you to the
matrix A menu. If you enter a dimension that is too large, the
calculator will display INVALID (I) and the program will halt.
You'll have to restart it by pressing XEQ M ENTER.
After you've specified the dimension, the program will automatically proceed to
the matrix editing mode described below.
Editing the Matrix A
To edit the entries of A, press 2 R/S from the
matrix A menu. The program will begin in the upper left corner
of the matrix and proceed left to right, top to bottom (the same way you
read English text). For each entry, it will first briefly display the
indices of that entry (the number above the indices is N):
After a brief pause, execution will automatically continue, and the program
will display the existing value and prompt for the new value of the entry
whose indices were just displayed:
To keep the existing value, just press R/S. Otherwise, enter
the new value before pressing R/S. If you've forgotten which
entry you are about to change, you can press the
x↔y key to retrieve the row and column
indices to the display. If you've already performed calculations that have
altered the stack, just press R↓ a few times. The
indices are probably still on the stack (as a bracketed vector).
At any time during editing, you can change which entry is being edited. When
the program is stopped awaiting a new value for an entry, you can store new
row and column indices into memory registers R and
C respectively. When you then enter a new value and press
R/S, it will be stored in the newly specified location and
editing will resume from there.
After editing the last entry of A, the program will return to
the matrix A menu.
Viewing the Matrix A or A-1
To examine A (or result matrix A-1),
press 3 R/S from the matrix A menu. The program
will proceed in the same way as during editing, first briefly displaying the
indices of each entry. After a brief pause, the program will display the
value of the entry whose indices were just displayed:
Press R/S to proceed to the next entry. If you store new row
and column indices into memory registers R and
C while the program is stopped, the next entry displayed will
be the one whose indices you specified, and viewing will continue from
there.
When you've examined the last entry in A, the program will return
to the matrix A menu.
Entering the Vector b
Pressing 2 R/S from the main menu will display the vector
b menu:
The menu choices are:
-
Edit the entries in vector b.
-
View the entries in b.
Note that there is no choice number 1. The choices are numbered 2 and 3 for
consistency with the menu for matrix A.
Pressing R/S without selecting a choice will return you to the
main menu.
Editing the Vector b
Press 2 R/S from the vector b menu to edit the
entries of b. The program will begin at the top of b.
Editing b proceeds the same way as editing A,
except that there is only a single index (the row). During editing, you can
change which entry is being edited by storing a new row number in memory
register R.
After editing the last entry of b, the program will return to
the vector b menu.
Viewing the Vector b or x
To examine b (or solution vector x after solving the
linear system), press 3 R/S from the vector b
menu. Viewing b (or x) proceeds the same way as
viewing A, except that there is only a single index. During
viewing, you can change which entry is to be viewed next by storing a new
row number in memory register R.
Solving the System Ax=b
If you're at the matrix A or vector b menus, press
R/S to return to the main menu. Then press 3 R/S to
solve the system of equations. First, the program will display a time estimate
(in seconds):
Press R/S to continue. After a while (a long while for a
really large system), the matrix multi-tool will display the computed
determinant:
Press R/S to return to the main menu. The results can be found
as follows:
-
A-1 will have replaced A.
You can examine A-1 by pressing
1 R/S at
the main menu, and then 3 R/S at the matrix A menu.
-
Solution vector x will have replaced b.
You can examine x by pressing
2 R/S at
the main menu, and then 3 R/S at the vector b menu.
-
The determinant is stored in memory register
D, which you
can examine by pressing RCL D.
Sometimes there is no solution. If this turns out to be the case, the program
will display the message SINGULAR. Pressing R/S will
then return you to the main menu.
Solving for Another Vector b
You can solve additional systems for the same matrix A and
different vectors b by entering new values for the entries of
b, and then running the solver again. So long as
A-1 has not been overwritten by editing A,
the matrix multi-tool will solve these additional systems by just computing
x = A-1b, which is much
faster (O(N2))
than the full solution process (O(N3)).
Restoring A and b
If you have not overwritten A-1 or x since
the last system you've solved, you can undo the solution by pressing
4 R/S from the main menu. This will restore matrix A
and the most recently entered vector b. If you try to perform
the undo operation when A-1 or x have been
modified, the program displays the message CANNOT UNDO and
returns to the main menu.
Performing Matrix-Vector Multiplication
The built-in matrix-vector multiplication routine that the matrix multi-tool
uses to solve additional systems when matrix A hasn't changed is
also available directly for your use. After entering A and
b as described earlier, pressing 5 R/S from the main
menu will compute the matrix-vector product of A and b.
The result vector will replace b, and can be examined the same way
b can, by pressing 2 R/S at the main menu, and then
3 R/S at the vector b menu. The matrix A is
unaltered. Another multiplication of A by a different b
vector can be carried out by entering the new vector and invoking the
multiplication.
Note that the undo operation (4 R/S from the main menu) does not
apply to matrix-vector multiplication.
Example
Solve the following system of equations:
3.8x1 + 7.2x2 = 16.5
1.3x1 - 0.9x2 = -22.1
| Keystrokes | Display | Description |
| XEQ M ENTER | 1A2b 3SoL4Un5× |
| 1 R/S | 1DIM 2ED 3VIEW |
| 1 R/S | N? |
| 2 R/S | [1,1] A? |
| 3.8 R/S | [1,2] A? |
| 7.2 R/S | [2,1] A? |
| 1.3 R/S | [2,2] A? |
| 0.9 +/- R/S | 1DIM 2ED 3VIEW |
| R/S | 1A2b 3SoL4Un5× |
| 2 R/S | 2ED 3VIEW |
| 2 R/S | [1] B? |
| 16.5 R/S | [2] B? |
| 22.1 +/- R/S | 2ED 3VIEW |
| R/S | 1A2b 3SoL4Un5× |
| 3 R/S | T= 1.4720 |
| R/S | D= -12.7800 |
| R/S | 1A2b 3SoL4Un5× |
| 2 R/S | 2ED 3VIEW |
| 3 R/S | [1] B= -11.2887 |
| R/S | [2] B= 8.2496 |
| R/S | 2ED 3VIEW |
| R/S | 1A2b 3SoL4Un5× |
Performance
Compared to the built-in matrix operations of an HP-15C or HP-42S, the matrix
multi-tool is quite slow, but still quite usable for real problems.
Furthermore, due to the larger built-in memory of the HP 35s, it can solve
larger problems than the 15C or 42S can. The following table gives the
approximate times for solving different sizes of systems using the matrix
multi-tool:
|
Size (N)
|
Solve Ax = b
|
Compute x = A-1b or Multiply Ab
|
|
2
|
4 sec
|
1 sec
|
|
3
|
8 sec
|
2 sec
|
|
4
|
14 sec
|
3 sec
|
|
5
|
26 sec
|
4 sec
|
|
6
|
43 sec
|
5 sec
|
|
7
|
1 min
|
7 sec
|
|
8
|
1½ min
|
8 sec
|
|
9
|
2 min
|
10 sec
|
|
10
|
3 min
|
13 sec
|
|
11
|
4 min
|
15 sec
|
|
12
|
5½ min
|
18 sec
|
|
13
|
7 min
|
21 sec
|
|
14
|
8½ min
|
25 sec
|
|
15
|
10½ min
|
28 sec
|
|
16
|
13 min
|
32 sec
|
|
17
|
15½ min
|
36 sec
|
|
18
|
18 min
|
41 sec
|
Program Listing
| Line | Instruction | Comments |
| M001← | LBL M |
| M002 | CLx |
| M003 | SF 10 |
| M004← | EQN 1A2b 3SoL4Un5× |
| M005 | CF 10 |
| M006 | x=0? |
| M007 | RTN |
| M008 | 1 |
| M009 | x=y? |
| M010 | GTO M036 |
| M011 | R↓ |
| M012 | 2 |
| M013 | x=y? |
| M014 | GTO M057 |
| M015 | R↓ |
| M016 | 3 |
| M017 | x≠y? |
| M018 | GTO M021 |
| M019 | XEQ M208 |
| M020 | GTO M001 |
| M021← | R↓ |
| M022 | 4 |
| M023 | x≠y? |
| M024 | GTO M027 |
| M025 | XEQ M183 |
| M026 | GTO M001 |
| M027← | R↓ |
| M028 | 5 |
| M029 | x≠y? |
| M030 | GTO M034 |
| M031 | XEQ M396 |
| M032 | CF 2 |
| M033 | GTO M001 |
| M034← | XEQ M179 |
| M035 | GTO M001 |
| M036← | CLx |
| M037 | SF 10 |
| M038 | EQN 1DIM 2ED 3VIEW |
| M039 | CF 10 |
| M040 | x=0? |
| M041 | GTO M001 |
| M042 | SF 1 |
| M043 | 1 |
| M044 | x=y? |
| M045 | GTO M074 |
| M046 | R↓ |
| M047 | 2 |
| M048 | x=y? |
| M049 | GTO M095 |
| M050 | R↓ |
| M051 | CF 1 |
| M052 | 3 |
| M053 | x=y? |
| M054 | GTO M095 |
| M055 | XEQ M179 |
| M056 | GTO M036 |
| M057← | CLx |
| M058 | SF 10 |
| M059 | EQN 2ED 3VIEW |
| M060 | CF 10 |
| M061 | x=0? |
| M062 | GTO M001 |
| M063 | SF 1 |
| M064 | 2 |
| M065 | x=y? |
| M066 | GTO M141 |
| M067 | R↓ |
| M068 | CF 1 |
| M069 | 3 |
| M070 | x=y? |
| M071 | GTO M141 |
| M072 | XEQ M179 |
| M073 | GTO M057 |
| M074← | INPUT N |
| M075 | IP |
| M076 | 2 |
| M077 | x>y? |
| M078 | GTO M081 |
| M079 | XEQ M085 |
| M080 | GTO M095 |
| M081← | SF 10 |
| M082 | EQN N TOO SMALL |
| M083 | CF 10 |
| M084 | GTO M036 |
| M085← | RCL N |
| M086 | ENTER |
| M087 | ENTER |
| M088 | + |
| M089 | 1 |
| M090 | + |
| M091 | x |
| M092 | STO I |
| M093 | STO (I) |
| M094 | RTN |
| M095← | 1 |
| M096 | STO R |
| M097 | STO C |
| M098← | XEQ M133 |
| M099 | STO I |
| M100 | RCL R |
| M101 | RCL N |
| M102 | x<y? |
| M103 | GTO M036 |
| M104 | EQN [R,C] |
| M105 | PSE |
| M106 | FS? 1 |
| M107 | GTO M119 |
| M108← | 1 |
| M109 | STO+ C |
| M110 | RCL C |
| M111 | RCL− N |
| M112 | x≤0? |
| M113 | GTO M116 |
| M114 | STO C |
| M115 | STO+ R |
| M116← | FS? 1 |
| M117 | RTN |
| M118 | REGZ |
| M119← | RCL (I) |
| M120 | STO A |
| M121 | FS? 1 |
| M122 | GTO M125 |
| M123 | VIEW A |
| M124 | GTO M098 |
| M125← | INPUT A |
| M126 | CF 0 |
| M127 | XEQ M133 |
| M128 | STO I |
| M129 | R↓ |
| M130 | STO (I) |
| M131 | XEQ M108 |
| M132 | GTO M098 |
| M133← | RCL C |
| M134 | 1 |
| M135 | − |
| M136 | RCL× N |
| M137 | RCL+ R |
| M138 | 1 |
| M139 | − |
| M140 | RTN |
| M141← | 1 |
| M142 | STO R |
| M143← | XEQ M171 |
| M144 | STO I |
| M145 | RCL R |
| M146 | RCL N |
| M147 | x<y? |
| M148 | GTO M057 |
| M149 | EQN [R] |
| M150 | PSE |
| M151 | FS? 1 |
| M152 | GTO M156 |
| M153 | 1 |
| M154 | STO+ R |
| M155 | R↓ |
| M156← | RCL (I) |
| M157 | STO B |
| M158 | FS? 1 |
| M159 | GTO M162 |
| M160 | VIEW B |
| M161 | GTO M143 |
| M162← | INPUT B |
| M163 | CF 2 |
| M164 | XEQ M171 |
| M165 | STO I |
| M166 | R↓ |
| M167 | STO (I) |
| M168 | 1 |
| M169 | STO+ R |
| M170 | GTO M143 |
| M171← | RCL N |
| M172 | x2 |
| M173 | ENTER |
| M174 | + |
| M175 | RCL+ R |
| M176 | 1 |
| M177 | − |
| M178 | RTN |
| M179← | SF 10 |
| M180 | EQN INVALID CMD |
| M181 | CF 10 |
| M182 | RTN |
| M183← | FS? 0 |
| M184 | GTO M186 |
| M185 | GTO M188 |
| M186← | FS? 2 |
| M187 | GTO M192 |
| M188← | SF 10 |
| M189 | EQN CANNOT UNDO |
| M190 | CF 10 |
| M191 | RTN |
| M192← | XEQ M215 |
| M193 | RCL D |
| M194 | 1/x |
| M195 | STO D |
| M196 | CF 0 |
| M197 | CF 2 |
| M198 | RTN |
| M199← | RCL N |
| M200 | x2 |
| M201 | STO I |
| M202 | ENTER |
| M203 | + |
| M204 | STO J |
| M205 | RCL+ N |
| M206 | STO E |
| M207 | RTN |
| M208← | FS? 0 |
| M209 | GTO M392 |
| M210 | XEQ M215 |
| M211 | SF 0 |
| M212 | SF 2 |
| M213 | VIEW D |
| M214 | RTN |
| M215← | RCL N |
| M216 | 3 |
| M217 | yx |
| M218 | 0.184 |
| M219 | x |
| M220 | STO T |
| M221 | VIEW T |
| M222← | XEQ M199 |
| M223 | CLx |
| M224← | DSE J |
| M225 | STO (J) |
| M226 | DSE I |
| M227 | GTO M224 |
| M228← | 1 |
| M229 | STO (J) |
| M230 | RCL+ N |
| M231 | STO+ J |
| M232 | RCL J |
| M233 | RCL E |
| M234 | x>y? |
| M235 | GTO M228 |
| M236 | 1 |
| M237 | STO D |
| M238 | CLx |
| M239 | STO K |
| M240 | RCL N |
| M241 | STO R |
| M242← | RCL R |
| M243 | 1 |
| M244 | x≥y? |
| M245 | GTO M325 |
| M246 | − |
| M247 | STO R |
| M248 | STO P |
| M249 | RCL K |
| M250 | STO I |
| M251 | STO J |
| M252 | RCL (I) |
| M253 | ABS |
| M254 | STO T |
| M255← | 1 |
| M256 | STO+ I |
| M257 | RCL T |
| M258 | RCL (I) |
| M259 | ABS |
| M260 | x≤y? |
| M261 | GTO M265 |
| M262 | STO T |
| M263 | RCL I |
| M264 | STO J |
| M265← | DSE P |
| M266 | GTO M255 |
| M267 | RCL J |
| M268 | RCL K |
| M269 | x=y? |
| M270 | GTO M293 |
| M271 | STO I |
| M272 | RCL T |
| M273 | x≠0? |
| M274 | GTO M279 |
| M275 | SF 10 |
| M276 | EQN SINGULAR |
| M277 | CF 10 |
| M278 | RTN |
| M279← | RCL D |
| M280 | +/− |
| M281 | STO D |
| M282← | RCL E |
| M283 | RCL J |
| M284 | x≥y? |
| M285 | GTO M293 |
| M286 | x↔ (I) |
| M287 | x↔ (J) |
| M288 | x↔ (I) |
| M289 | RCL N |
| M290 | STO+ I |
| M291 | STO+ J |
| M292 | GTO M282 |
| M293← | RCL R |
| M294 | STO P |
| M295← | RCL K |
| M296 | STO I |
| M297 | RCL+ P |
| M298 | STO J |
| M299 | RCL (J) |
| M300 | RCL÷ (I) |
| M301 | STO T |
| M302 | CLx |
| M303 | STO (J) |
| M304← | RCL N |
| M305 | STO+ I |
| M306 | STO+ J |
| M307 | RCL E |
| M308 | RCL J |
| M309 | x≥y? |
| M310 | GTO M315 |
| M311 | RCL (I) |
| M312 | RCL× T |
| M313 | STO− (J) |
| M314 | GTO M304 |
| M315← | DSE P |
| M316 | GTO M295 |
| M317 | RCL K |
| M318 | STO I |
| M319 | RCL (I) |
| M320 | STO× D |
| M321 | 1 |
| M322 | RCL+ N |
| M323 | STO+ K |
| M324 | GTO M242 |
| M325← | RCL K |
| M326 | STO I |
| M327 | RCL (I) |
| M328 | STO× D |
| M329 | RCL N |
| M330 | STO R |
| M331← | RCL K |
| M332 | STO J |
| M333 | RCL (J) |
| M334 | STO T |
| M335 | 1 |
| M336 | STO (J) |
| M337 | STO P |
| M338← | RCL N |
| M339 | STO +J |
| M340 | RCL E |
| M341 | RCL J |
| M342 | x≥y? |
| M343 | GTO M347 |
| M344 | RCL T |
| M345 | STO÷ (J) |
| M346 | GTO M338 |
| M347← | DSE R |
| M348 | GTO M363 |
| M349 | RCL N |
| M350 | x2 |
| M351 | STO K |
| M352 | STO J |
| M353 | CLx |
| M354 | STO I |
| M355← | RCL (J) |
| M356 | STO (I) |
| M357 | 1 |
| M358 | STO+ I |
| M359 | STO+ J |
| M360 | DSE K |
| M361 | GTO M355 |
| M362 | RTN |
| M363← | RCL K |
| M364 | STO I |
| M365 | RCL− P |
| M366 | STO J |
| M367 | RCL (J) |
| M368 | STO T |
| M369 | CLx |
| M370 | STO (J) |
| M371← | RCL N |
| M372 | STO+ I |
| M373 | STO+ J |
| M374 | RCL E |
| M375 | RCL J |
| M376 | x≥y? |
| M377 | GTO M382 |
| M378 | RCL (I) |
| M379 | RCL× T |
| M380 | STO− (J) |
| M381 | GTO M371 |
| M382← | 1 |
| M383 | STO+ P |
| M384 | RCL P |
| M385 | RCL R |
| M386 | x≥y? |
| M387 | GTO M363 |
| M388 | 1 |
| M389 | RCL+ N |
| M390 | STO− K |
| M391 | GTO M331 |
| M392← | XEQ M396 |
| M393 | SF 0 |
| M394 | SF 2 |
| M395 | RTN |
| M396← | RCL N |
| M397 | x2 |
| M398 | 0.125 |
| M399 | x |
| M400 | STO T |
| M401 | VIEW T |
| M402← | XEQ M199 |
| M403 | RCL N |
| M404 | STO R |
| M405← | CLx |
| M406 | STO T |
| M407 | RCL R |
| M408 | 1 |
| M409 | − |
| M410 | STO I |
| M411 | RCL E |
| M412 | RCL− N |
| M413 | STO J |
| M414← | RCL (I) |
| M415 | RCL× (J) |
| M416 | STO+ T |
| M417 | RCL N |
| M418 | STO+ I |
| M419 | 1 |
| M420 | STO+ J |
| M421 | RCL E |
| M422 | RCL J |
| M423 | x<y? |
| M424 | GTO M414 |
| M425 | RCL T |
| M426 | STO (I) |
| M427 | DSE R |
| M428 | GTO M405 |
| M429 | RCL N |
| M430 | STO− J |
| M431← | RCL (I) |
| M432 | STO (J) |
| M433 | 1 |
| M434 | STO+ I |
| M435 | STO+ J |
| M436 | RCL E |
| M437 | RCL J |
| M438 | x<y? |
| M439 | GTO M431 |
| M440 | SF 0 |
| M441 | SF 2 |
| M442 | RTN |
Length: 1455, Checksum: 9A4A
Note 1: The keystrokes to enter line M004 are:
EQN 1 RCL A 2 L.R. 5 SPACE 3 RCL S BASE 7 RCL L 4 RCL U SUMS 1 5 × ENTER
Note 2: To enter the REGZ instruction, press any function key that
displays a menu of choices (such as FLAGS), press the
R↓ key, and select z.
Note 3: There is a bug in the HP 35s (and HP 33s) firmware that if a program
last stopped to display an EQN message, it will be uninterruptible
until it stops for some other reason (a VIEW, INPUT,
or STOP instruction). By computing a time estimate, we have an
excuse to use a VIEW instruction (to display the time estimate)
before entering into a potentially long-running computation.
Registers and Flags
|
Register
|
Use
|
|
A
|
|
B
|
|
C
|
|
D
|
|
E
|
|
I, J
|
|
K
|
|
N
|
|
P
|
|
R
|
|
T
|
|
0…N2-1
|
|
N2…2N2-1
|
|
2N2…2N2+N-1
|
|
2N2+N
|
Revision History
2007-Nov-07 — Initial release.
2007-Nov-18 — Made the matrix dimensioning function and solver callable
so they can be used by other programs I might write.
2007-Nov-20 — Compute and display time estimate before invoking solvers.
This works around the HP 35s bug that programs are not interruptible if
the last thing displayed was an EQN message, which can be
disconcerting during an 18 minute matrix inversion.
2008-Apr-03 — Made the matrix multiplication routine accessible from the
main menu (5 R/S), and also callable as a subroutine from
other programs.
Calling Matrix Multi-Tool Subroutines from Other Programs
Several subroutines in the matrix multi-tool can be readily used from other
programs. Note that the line numbers of these routines might change as I post
future revisions to this program.
M085: Set Up Matrix and Vector Storage
Sets up memory to hold an N×N matrix A,
an N×N scratch matrix, and an N-element
vector b. The dimension N is expected to be in register
N.
On return, register I will contain
2N2+N, the indirect address of the first
register after the allocated memory, and that register will also contain its
own address (to ensure that all the required memory remains allocated even if
the last entries in b are zero).
M133: Compute Index of Arc
Given row and column indices in registers R and C
respectively, compute the index of Arc in the memory
allocated above. Requires that register N still contains the
dimension, N, of matrix A and vector b.
M171: Compute Index of br
Given a row index in register R, compute the index of
br in the memory allocated above. Requires that register
N still contains the dimension, N, of matrix
A and vector b.
M222: Solve Ax=b or Compute A-1 by Gaussian Elimination
Solves the system Ax=b for matrix A and vector
b. The dimension must be in register N. Matrix
A is expected to be stored column-wise in indirect registers 0
through N2-1. Vector b is expected to be
stored in indirect registers 2N2 through
2N2+N-1.
On return, A will have been replaced by its inverse
(A-1) and b will have been replaced by
x. The determinant of A will be in register
D. This subroutine also uses registers E,
I, J, K, P, R,
and T, and indirect registers N2 through
2N2-1.
An alternate entry point for this subroutine is M215,
which will first display a time estimate (T=...). The Gaussian
elimination will commence only after the user presses R/S. This
works around an HP 35s firmware bug where a program is uninterruptible if the
last thing displayed was an EQN message.
M402: Compute Matrix-Vector Product Ab
Computes the matrix-vector product Ab for matrix A and
vector b. The dimension must be in register N. Matrix
A is expected to be stored column-wise in indirect registers 0
through N2-1. Vector b is expected to be
stored in indirect registers 2N2 through
2N2+N-1.
On return, A will be unchanged and b will have been
replaced by the product Ab. This subroutine also uses registers
E, I, J, R, and
T, and indirect registers N2 through
N2+N-1.
An alternate entry point for this subroutine is M396,
which will first display a time estimate (T=...). The
matrix-vector multiplication will commence only after the user presses
R/S. Again, this is useful for working around the uninterruptible
program bug.
Why I Wrote this Program
One of my first programmable calculators was a Texas Instruments SR-52 that I
purchased at Eaton's for $149 back in 1978 or so. At that time, the TI-59 had
already been introduced and the store was clearing out the SR-52. This
calculator had 224 steps of program memory, 20 registers, and a magnetic card
reader. It was only slightly less powerful than the HP-67.
When I was in the 10th or 11th grade, we learned how to solve systems of linear
equations using matrices, Gaussian elimination, and back substitution. After
learning the method, it became clear to me that it would be easy to do on a
computer, and I decided I'd try to program the SR-52 to do it. My teacher (who
also taught computer science), was all in favour of the idea, and even said I
could use the program during a test. He figured if I was smart enough to
program it, especially in only 224 program steps, I obviously knew the
algorithm inside out and backwards. Well, I managed to fit it onto the SR-52,
although it was limited to 2x2 and 3x3 systems due to the limited number of
storage registers. Of course with only 224 steps, there was no room for a user
interface; I had to manually store the matrix elements into the appropriate
registers.
Now, about 28 years later, an expanded version of this program came to mind as
an ideal second project on the HP 35s, especially since my earlier HP
calculators (41CX with Advantage Pac, and 42S) had this capability built in.
This program will also prove useful as a subroutine in a polynomial curve
fitting program I have planned for the future.
|
|
|
|
Buy Stefan a coffee!
If you've found this article
useful, consider leaving a donation
to help support
Stefan's Historical Computing Devices.
|
|
|
|
|
Last updated Wednesday April 23, 2008.
|
E-mail Stefan
|
|
|
|
Disclaimer:
Although every effort has been made to ensure accuracy and
reliability, the information on this web page is presented without
warranty of any kind, and Stefan Vorkoetter assumes no liability for direct or
consequential damages caused by its use.
It is up to you, the reader, to determine the suitability of, and
assume responsibility for, the use of this information.
Copyright:
All materials on this web site, including the text, images, and HTML
mark-up, are Copyright © 2008 by Stefan Vorkoetter unless
otherwise noted. All rights reserved. Unauthorized duplication
prohibited. You may link to this site or pages within it, but
you may not link directly to images on this site, and you may
not copy any material from this site to another web site or
other publication without express written permission. You may make
copies for your own personal use.
|
|