.

Complex Matrix to Row Reduced Echelon Form for HP-41cv/cx

This program transforms a complex matrix into row reduced echelon form. In addition it computes the inverse and the determinant of its left square part. To do so it uses a maximum pivot method which reverses the complex matrix on place.

History

The origin of this program is dusty.  My notes refer to a program section published under “Network Analysis” [1], but I can’t find such a reference.  Perhaps it was from the book “Handbook of electronic design and analysis procedures using programmable calculators” [3]. Then again, maybe I wrote or at the very least, added an user interface in October 1986.

Instructions

Start with XEQ “CMA” and the program will walk you through.

Method

The CMA program handles the 3 matrix problems simultaneously: 1) calculate the inverse of a complex square matrix; 2) calculate the determinant of a complex square matrix; 3) solve a system of complex equations or reduce a system of complex parameter equations.

Reversing the left square matrix on place requires almost no extra time over that required for just reducing a matrix. The latter method (when using the MA program) includes redundant computations known to give zero results. The CMA routine simply avoids this by replacing the pivots and the elements reduced to 0 by their matrix counterparts.

The elements of the input matrix will be stored row by row as sets of two numbers representing their polar form (magnitude first) by the input routine. The i/o mode (polar/rect) can be chosen by the user.

Consider the following matrix equations:

Exchanging two columns means exchanging two variables:

On the contrary, in the inverse of the matrix, two rows need to be exchanged for exchanging two variables. In the CMA program, when the largest elements is found out of the pivot candidates left, it is placed on the main diagonal of the square matrix by exchanging two columns (row index=column index); the exchange is saved in an extra vector. When the reducing process is finishes, the inverse of the matrix and the solutions can be rearranged to their appropriate form by reapplying the exchanges in reverse order, but this time on the rows.

This method allows us to reverse matrices on place with a maximum pivot algorithm.

Examples

  1. As a first example, we will tackle problem 3 from the PPC ROM User Manual on page 263 [2]. Note that a real matrix can be written as a complex matrix with all angles 0.

    Note that the HP-41 can handle complex numbers with negative magnitudes.
    :
  2. Another example:

    The last column gives the solution of the system of equations represented by the input matrix. The other columns are the corresponding elements of the inverse of the left square part of the input matrix.  Running CMA on this matrix should transform it back into the input matrix. Because of rounding errors, this is not completely true.
    In the above example, the matrix reads the same in SCI 7 mode. This gives a good indication of the accuracy to be expected from the maximum pivot method used. One warning however : do not trust the results of CMA when the determinant of the square matrix turns out to be unexpectedly small in magnitude in comparison with the magnitudes of the elements of the input matrix! In this case you are dealing with a so called “badly conditioned system”. You can always check this by running CMA twice on the input matrix, and by reading the Magn(Determinant) using the  E  key.

Listing

  • Requires
    • X-Functions module on the HP-41cv
  • Available as
  • Size
    • 783 bytes including END (785 if long jumps); 7 magnetic tracks
    • Long Jumps: at line 103 and  304.
  • Registers used
    • R04, magnitude of the determinant
    • R05, angle of the determinant
    • R06, scratch
    • R07, starting address of the matrix (initiated to 16)
    • R08, # of columns * 2
    • R09, # of rows
    • R10, ISG pointer to exchange pointer stack
    • R11, DSE pointer to magnitudes
    • R12, main row counter
    • R13, column exchange ISG constant
    • R14, scratch
    • R15, scratch
    • R M, scratch
    • R O, scratch
    • R N, save flag register d
;  /-------------------------------------------------------------------\
;  |                  C o m p l e x    M a t r i x                     |
;  |                   to Row Reduced Echelon Form                     |
;  |                                                                   |
;  |                          for the HP-41                            |
;  \-------------------------------------------------------------------/
;
;     http://www.coertvonk.com/technology/hp41/complex-matrix-4555

01	LBL "CMAT"
02	LBL A
03	"COMPL MATRIX"
04	AVIEW
05	TONE 89
06	PSE
07	3
08	STO 00
09	16
10	STO 07
11	"R^C ?"
12	PROMPT
13	ST+ X
14	STO 08
15	X<>Y
16	STO 09
17	STO Z
18	*
19	+
20	15
21	+
22	"RESIZE="
23	CF 29
24	FIX 0
25	ARCL X
26	PROMPT
27	SF 09
28	GTO 12

29	LBL B
30	CF 09
31	LBL 12
32	CF 29
33	RCL 07
34	STO 04
35	RCL 08
36	RCL 09
37	*
38	STO 03
39	LBL 13
40	RCL 04
41	XEQ 18
42	ISG X
43	""
44	FIX 0
45	2
46	ST/ Y
47	"("
48	ARCL Z
49	>","
50	ARCL Y
51	>")"
52	FC? 09
53	GTO 15
54	FS? 01
55	>"=I^R ?"
56	FC? 01
57	>"=M^< ?"
58	0
59	TONE 89
60	PROMPT
61	FC? 01
62	X<>Y
63	FS? 01
64	R-P
65	STO IND 04
66	X<>Y
67	ISG 04
68	""
69	STO IND 04
70	GTO 17

71	LBL 15
72	ASTO 05
73	ENG IND 00
74	RCL IND 04
75	ISG 04
76	""
77	RCL IND 04
78	X<>Y
79	FC? 01
80	GTO 28
81	P-R
82	"R"
83	LBL 28
84	FC? 01
85	"M"
86	ARCL 05
87	ARCL X
88	AVIEW
89	PSE
90	PSE
91	FS? 01
92	"I"
93	FC? 01
94	"<"
95	ARCL 05
96	ARCL Y
97	AVIEW
98	LBL 17
99	ISG 04
100	""
101	DSE 03
102	DSE 03
103	GTO 13
104	RTN

105	LBL C
106	FIX 0
107	CF 29
108	2
109	ST* Y
110	RDN
111	XEQ 19
112	DSE X
113	STO 04
114	" R"
115	ARCL X
116	ISG X
117	""
118	>"+"
119	ARCL X
120	AVIEW
121	2
122	STO 03
123	RDN
124	CF 09
125	GTO 13
126	RTN

127	LBL E
128	"D="
129	ARCL 04
130	AVIEW
131	RTN

132	LBL 24
133	X<>Y
134	STO O
135	X<>Y
136	MOD
137	ST- O
138	LASTX
139	ST/ O
140	CLX
141	X<> O
142	X<> Y
143	RTN

144	LBL 25
145	XEQ 20
146	X<>Y
147	LBL 21
148	ST* IND Y
149	ISG Y
150	GTO 21
151	RTN

152	LBL 26
153	RCL IND Y
154	X<> IND Y
155	STO IND Z
156	RDN
157	ISG X
158	""
159	ISG Y
160	GTO 26
161	RTN

162	LBL 20
163	RCL 08
164	*
165	RCL 07
166	+
167	RCL X
168	RCL 08
169	ST- Z
170	SIGN
171	-
172	 E3
173	/
174	+
175	RTN

176	LBL 18
177	RCL 07
178	-
179	RCL 08
180	XEQ 24
181	ISG Y
182	""
183	ISG X
184	""
185	RTN

186	LBL 19
187	X<> 08
188	ST- 08
189	*
190	ST+ 08
191	X<> L
192	X<> 08
193	1
194	-
195	RCL 07
196	+
197	RTN

198	LBL 27
199	SIGN
200	CLX
201	LBL 23
202	STO IND L
203	ISG L
204	GTO 23
205	RTN

206	LBL F
207	SF 01
208	"R"
209	AVIEW
210	RTN

211	LBL G
212	CF 01
213	"P"
214	AVIEW
215	RTN

216	LBL D
217	CLA
218	 E-3
219	RCL 07
220	RCL 08
221	RCL 09
222	STO 12
223	*
224	+
225	STO 11
226	*
227	-2
228	LASTX
229	+
230	X<> 11
231	X<> Z
232	-
233	+
234	STO 10
235	LASTX
236	RCL 07
237	1
238	STO 04
239	-
240	+
241	RCL 08
242	 E-5
243	ST+ 11
244	ST+ 11
245	*
246	+
247	STO 13
248	0
249	STO 05
250	RCL 08
251	2 E3
252	/
253	RCL 09
254	+
255	XEQ 14
256	GTO 00

257	LBL 06
258	SF IND X
259	LBL 00
260	ISG X
261	GTO 06
262	LBL 16
263	RCL 11
264	STO O
265	RCL 09
266	STO 14
267	CLX
268	LBL 02
269	RCL 08
270	2
271	/
272	STO M
273	LBL 03
274	RDN
275	FC? IND 14
276	GTO 04
277	RCL 08
278	ST- O
279	DSE 14
280	GTO 03
281	RDN
282	GTO 05

283	LBL 04
284	FS? IND M
285	GTO 01
286	RCL IND O
287	ABS
288	X<Y?
289	GTO 00
290	RCL O
291	STO 15
292	LBL 00
293	X<>Y
294	LBL 01
295	DSE O
296	DSE M
297	GTO 04
298	DSE 14
299	GTO 02
300	LBL 05
301	X#0?
302	GTO 00
303	STO 04
304	GTO 14

305	LBL 00
306	RCL 15
307	INT
308	STO 15
309	XEQ 18
310	STO M
311	X<>Y
312	STO 06
313	1
314	X<> IND 15
315	ST* 04
316	1/X
317	STO 14
318	ISG 15
319	""
320	0
321	X<> IND 15
322	ST+ 05
323	STO 15
324	R^
325	RCL 13
326	+
327	RCL 06
328	SF IND X
329	ST+ X
330	DSE X
331	LASTX
332	+
333	STO O
334	X=Y?
335	GTO 00
336	XEQ 26
337	RCL M
338	1
339	+
340	RCL 13
341	+
342	RCL O
343	-1
344	ST* 04
345	-
346	XEQ 26
347	RCL M
348	 E
349	+
350	2
351	/
352	 E
353	XEQ 19
354	 E3
355	/
356	RCL 06
357	 E
358	XEQ 19
359	+
360	RCL 08
361	 E6
362	/
363	+
364	STO IND 10
365	ISG 10
366	LBL 00
367	2 E-5
368	ST+ 07
369	RCL 14
370	RCL 06
371	XEQ 25
372	CLX
373	RCL 08
374	-
375	1
376	+
377	RCL 15

378	LBL 09
379	ST- IND Y
380	ISG Y
381	GTO 09
382	RCL 07
383	INT
384	X<> 07
385	STO 14
386	1
387	+
388	STO 15
389	RCL 13
390	INT
391	RCL 06
392	RCL 08
393	*
394	+
395	1.001
396	*
397	RCL 08
398	-
399	1
400	+
401	STO 06
402	XEQ 14
403	LBL 07
404	RCL 14
405	INT
406	RCL 06
407	STO M
408	INT
409	X#Y?
410	GTO 00
411	RCL 08
412	ST+ 14
413	ST+ 15
414	GTO 11

415	LBL 00
416	RCL O
417	1
418	+
419	0
420	X<> IND Y
421	0
422	X<> IND O
423	LBL 10
424	RCL IND M
425	X<>Y
426	*
427	LASTX
428	X<> IND 14
429	X<> Z
430	ISG M
431	RCL IND M
432	X<>Y
433	+
434	X<>Y
435	LASTX
436	X<> IND 15
437	R^
438	P-R
439	R^
440	R^
441	P-R
442	X<> T
443	X<>Y
444	-
445	X<> Z
446	-
447	R-P
448	X<> IND 14
449	X<>Y
450	X<> IND 15
451	X<>Y
452	ISG 14
453	""
454	ISG 15
455	""
456	ISG M
457	GTO 10
458	LBL 11
459	ISG O
460	GTO 07
461	XEQ 14
462	DSE 12
463	GTO 16
464	GTO 00

465	LBL 08
466	RCL IND 10
467	REGSWAP
468	LBL 00
469	DSE 10
470	GTO 08
471	LBL 14
472	X<> N
473	X<> d
474	X<> N
475	END

References

[1] Origin unknown
Perhaps a section from “Network Analysis”
[2] Application program RRM for M1
John Kennedy, December 1981
PPC ROM User’s Manual, page 263-265
[3] Handbook of electronic design and analysis procedures using programmable calculators
Bruce K. Murdock
Coert Vonk

Coert Vonk

Independent Firmware Engineer at Los Altos, CA
Welcome to the things that I couldn’t find.This blog shares some of the notes that I took while deep diving into various fields.Many such endeavors were triggered by curious inquiries from students. Even though the notes often cover a broader area, the key goal is to help the them adopt, flourish and inspire them to invent new technology.
Coert Vonk

Latest posts by Coert Vonk (see all)

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Protected with IP Blacklist CloudIP Blacklist Cloud