Post Reply 
Need help debugging program on HP 35s
04-11-2015, 03:12 PM
Post: #1
Need help debugging program on HP 35s
I'm learning to program on the HP 35s; most of my experience programming an HP calculator is with the 41 series. I wrote a program to Solve Linear Systems. Its objective is to reduce the matrix on the upper right to a diagonal form with only ones in the diagonal. The determinant of this matrix is also computed and stored in named variable D.

Given a system of equations, for example:

2x + 3y + 5z + 4t = 39
-4x + 2y + z + 3t = 15
3x - y + 2z + 3t = 19
5x + 7y - 3z + 2t = 18

is re-written

39 = 2x + 3y + 5z + 4t
15 = -4x + 2y + z + 3t
19 = 3x - y + 2z + 3t
18 = 5x + 7y - 3z + 2t

storing these 20 numbers column-wise in R01 thru R20.

-If flag F00 is clear the pivots smaller than E-7 ( line 60 ) is regarded as zero
-If flag F00 is set, only zero is regarded as zero
-CF 01 = partial pivoting , SF 01 = no pivoting

There are 4 rows and 5 columns,

CF 00 CF 01
4 ENTER
5 XEQ "L" ENTER

Det A = 840 = Named Variable D

Registers R05 thru R16 now contain the unit matrix and registers R01 thru R04 contain the solution x = 1 , y = 2 , z = 3 , t = 4

When the program stops, D = det A.

Code:
L001 LBL "L"
L002 X<>Y
L003 .1
L004 %
L005 +
L006 STO N
L007 *
L008 LASTX
L009 FP
L010 -
L011 STO O
L012 1
L013 STO D       
L014 LASTX
L015 %
L016 REGZ
L017 IP
L018 +
L019 STO M
L020 FS? 1
L021 GTO L059
L022 IP
L023 RCL O
L024 FP
L025 +
L026 STO I
L027 0
L028 RCL(I)
L029 ABS 
L030 X<Y?
L031 GTO L036
L032 X<>Y
L033 CLX
L034 RCL I
L035 STO J
L036 RDN
L037 DSE I
L038 GTO L028
L039 RCL M
L040 STO I
L041 ENTER
L042 FP
L043 RCL J
L044 IP
L045 +
L046 STO J
L047 X=Y?
L048 GTO L059
L049 RCL(J)
L050 X<>(I)
L051 STO(J)
L052 DSE J
L053 RDN
L054 DSE I
L055 GTO L049
L056 RCL D
L057 +/-
L058 STO D
L059 CLX
L060 FS? 0
L061 GTO L063
L062 E-7
L063 RCL M
L064 STO I
L065 CLX
L066 RCL(I)
L067 STO* D
L068 ABS
L069 X<=Y?
L070 CLX
L071 X=0?
L072 STO D
L073 X=0?
L074 GTO L100
L075 LASTX
L076 ST/(I)
L077 DSE I
L078 GTO L076
L079 RCL O
L080 STO P
L081 RCL M
L082 STO I
L083 ENTER
L084 FP
L085 RCL P
L086 IP
L087 +
L088 X=Y?
L089 GTO L098
L090 STO J
L091 RCL(I)
L092 RCL*(J)
L093 STO-(J)
L094 DSE J
L095 RDN
L096 DSE I
L097 GTO L091
L098 DSE P
L099 GTO L081
L100 RCL N
L101 STO- O
L102 RCL O
L103 RCL M
L104 1
L105 -
L106 STO M
L107 X<=Y?
L108 CLX
L109 DSE M
L110 GTO L113
L111 RCL D
L112 RTN
L113 RCL M
L114 GTO L020

Program Notes:

Lines 28-38 Find the largest element of a column above the diagonal
Lines 49-55 Swap rows
Lines 59-78 Divides all the row by the pivot so this diagonal element becomes 1
Then this row is used to replace by 0 all the other elements of this column using linear combinations of rows.

Lines 81-89 Scans all the column to which belongs a given pivot ( = 1 now )
If the element of this column is the diagonal element ( line 88 X=Y? ) the process below is skipped ( GTO L098 ).

Lines 90-97 A linear combination of the rows is performed to replace the element of this column by 0.

The program isn't working quite right yet and I haven't been able to trace the error. Any help would be appreciated.
Find all posts by this user
Quote this message in a reply
04-11-2015, 07:56 PM
Post: #2
RE: Need help debugging program on HP 35s
You might find this program helpful:
A Matrix Multi-Tool for the HP 35s Programmable Calculator

Kind regards
Thomas
Find all posts by this user
Quote this message in a reply
04-12-2015, 12:18 PM (This post was last modified: 04-12-2015 12:23 PM by Jeff_Kearns.)
Post: #3
RE: Need help debugging program on HP 35s
(04-11-2015 03:12 PM)mbrethen Wrote:  I'm learning to program on the HP 35s;

Based on this article, you have some experience with this calculator and Stephan's program.

Jeff
Find all posts by this user
Quote this message in a reply
04-12-2015, 08:19 PM (This post was last modified: 04-13-2015 02:14 AM by mbrethen.)
Post: #4
RE: Need help debugging program on HP 35s
That was my first try at programming the 35s. I made some minor modifications to an existing program written by Mr. Hanson and used it along with the other program from Stefan, already mentioned, for some engineering classes I was taking at the time.

So, yeah, I'm still learning. After spending a week debugging this program I traced the errors to lines L091-L114.

Code:
L001 LBL "L"
L002 X<>Y
L003 .1
L004 %
L005 +
L006 STO N
L007 *
L008 LASTX
L009 FP
L010 -
L011 STO O
L012 1
L013 STO D       
L014 LASTX
L015 %
L016 REGZ
L017 IP
L018 +
L019 STO M
L020 FS? 1
L021 GTO L059
L022 IP
L023 RCL O
L024 FP
L025 +
L026 STO I
L027 0
L028 RCL(I)
L029 ABS 
L030 X<Y?
L031 GTO L036
L032 X<>Y
L033 CLX
L034 RCL I
L035 STO J
L036 RDN
L037 DSE I
L038 GTO L028
L039 RCL M
L040 STO I
L041 ENTER
L042 FP
L043 RCL J
L044 IP
L045 +
L046 STO J
L047 X=Y?
L048 GTO L059
L049 RCL(J)
L050 X<>(I)
L051 STO(J)
L052 DSE J
L053 RDN
L054 DSE I
L055 GTO L049
L056 RCL D
L057 +/-
L058 STO D
L059 CLX
L060 FS? 0
L061 GTO L063
L062 E-7
L063 RCL M
L064 STO I
L065 CLX
L066 RCL(I)
L067 STO* D
L068 ABS
L069 X<=Y?
L070 CLX
L071 X=0?
L072 STO D
L073 X=0?
L074 GTO L103
L075 LASTX
L076 ST/(I)
L077 DSE I
L078 GTO L076
L079 RCL O
L080 STO P
L081 RCL M
L082 STO I
L083 ENTER
L084 FP
L085 RCL P
L086 IP
L087 +
L088 X=Y?
L089 GTO L098
L090 STO J
L091 RCL(J)
L092 ENTER
L093 ENTER
L094 ENTER
L095 RCL*(I)
L096 STO-(J)
L097 DSE J
L098 RDN
L099 DSE I
L100 GTO L095
L101 DSE P
L102 GTO L081
L103 RCL O
L104 RCL- N
L105 STO O
L106 RCL M
L107 1
L108 -
L109 X>Y?
L110 GTO L114
L111 CLX
L112 RCL D
L113 RTN
L114 STO M
L115 DSE M
L116 RCL M
L117 GTO L020

I decided to replace those menu-driven programs with a library of matrix programs that use a control-number format similar to the 41 Advantage module.

So far, I have added the following to my library:
1. Storing a Matrix (which can be found here).
2. Addition & Subtraction
3. Multiplication
4. Norm of a Matrix
5. Trace of a Square Matrix
6. Transpose
a) General case
b) Square Matrix
7. Copying a Matrix

They are translations of Jean-Marc Baillard's programs for the 41.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)