Linear-algebra users --
The HP-15C was HP's first calculator with built-in support for linear-algebra functions, namely:
- Matrix arithmetic
- Solution of exactly-determined systems
- Matrix inversion
- Transpose and transpose-multiplication
- Residual
- Determinant
- Euclidian/Frobenius and row norms
- Utilities to support some operations for complex-valued matrices
However, the HP-15C was not designed as a full-featured tool for linear algebra; no built-in function to create an identity matrix is provided. This is not unreasonable, as keyboard space for functionality and RAM space for matrices is rather limited. Few linear-algebra problems that are convenient to solve on the HP-15C would require identity matrices.
(Interestingly enough, the HP-41 Advantage Pac and the HP-42S also lack built-in functions for creating identity matrices, although the HP-48 has the "IDN" function for that purpose.)
The HP-15C Advanced Functions Handbook (page 119) includes a 12-line program for creating an identity matrix:
LBL 8 42,21, 8
MATRIX 1 42,16, 1
LBL 9 42,21, 9
RCL 0 45 0
RCL 1 45 1
TEST 6 43,30, 6 (checks if off-diagonal element)
CLx 43 35
TEST 5 43,30, 5 (checks if on-diagonal element)
EEX 26
USER STO (i) u 44 24 (store 0 or 1 and increment element)
USER (no code) (exits USER mode)
GTO 9 22 9 (skipped when last element reached)
RTN 43 32
This program, although compact, requires the user to manually dimension the identity matrix and store its descriptor to the indirect register. Also, it runs slowly, because it determines and stores each matrix element individually.
Example:
5
ENTER
DIM E
RCL MATRIX E
STO I
GSB 8
(5x5 identity matrix E is produced in 28 seconds)
Here's my 25-line program that is easier to use and runs faster (but requires almost two more registers of storage space):
LBL .9 42,21,.9
x<>y 34
STO I 44 25 (stores matrix descriptor to indirect)
CLx 43 35
ENTER 36
DIM I 42,23,25 (zeroes out the matrix)
Rdn 33
Rdn 33
ABS 43 16
INT 43 44 ("normalizes" the matrix order)
ENTER 36
DIM I 42,23,25 (redimensions as zero-filled matrix)
STO 0 44 0
STO 1 44 1 (positions pointer at end)
/ 10 (creates 1, except if order is zero)
LBL .8 42,21,.8
STO (i) 44 24 (place 1 on diagonal element)
DSE 0 42, 5, 1 (decrement row pointer)
ABS 43 16 (a necessary "no op")
DSE 1 42, 5, 1 (decrement column pointer)
GTO .8 22 .8
CLx 43 35 (removes "1" from stack
RCL I 45 25 (column pointer reached 0; display result)
MATRIX 1 42,16, 1
RTN 43 32
This program requires that the user only recall the descriptor of the desired identity matrix (empty or not) to the stack, enter its desired order from 1 to 8 (space permitting), then execute the program. The positive integer portion of negative and fractional entered orders will be used. Only ones are stored to matrix elements, as the remainder of the matrix is already zero-filled.
Example:
RCL MATRIX E
5
GSB .9
(5x5 identity matrix E is produced in 7 seconds)
A sample application:
How close is the calculated inverse of matrix "A" (up to 4x4)?
- (Create matrix A)
- RCL MATRIX A
- RESULT C
- 1/x
- (Create identity matrix in B using program)
- RESULT B
- RCL MATRIX A
- RCL MATRIX C
- MATRIX 6 (residual calculation)
- (Read element-by-element error from matrix B)
- (Compute Frobenius/Euclidian or row norms of B if desired)
-- KS
Edited: 29 Apr 2006, 5:03 p.m.