HP Articles Forum
[Return to the Index ]
[ Previous | Next ]
A Third Order Complex Linear Equation Solver for the hp 33s
Posted by Palmer O. Hanson, Jr. on 20 June 2007, 10:27 p.m.
Introduction
In response to publication of my "Sixth Order Linear Equation Solver for the hp 33s" (Article No. 676) correspondent Gerson W. Barbosa wrote "... Now, a fourth or even a third order Complex Linear Equation Solver would be great, but that would be asking too much, I recognize." This article offers a third order solver.
The program which follows is not elegant. Users will see a lot of repeated code which could surely be compressed with subroutines. I didn't use many suboutines. Subroutines use labels, and labels are in short supply on the hp 33s. Program memory is not in short supply on the hp 33s.
Program Description
The program is essentially a modification of my "A Label Saving Simultaneous Equation Solution for the 33s" (Article No. 599) to use the complex arithmetic capability of the hp 33s. The solution is obtained using Cramer's rule. The L routine sets up initial conditions. The M routine provides input, sequencing through the subroutines and output. The D subroutine calculates the desired determinant. The V and X subroutines provide a circular shifting of the stored input data to set up the matrix needed for a particular determinant calculation.
The input and display of complex numbers of the form x + iy follows the convention established in section 9 of the manual. The imaginary part is in y (the upper level of the display) and the real part is in x (the lower level of the display).
The input part of the program mimics the INPUT function for single variables. A prompt which indicates the row and column to be entered is flashed; for example, the prompt "1,01" asks for the coefficient from the first row and first column and the prompt "2,04" asks for the second element of the vector. After the prompt the program stops with the previously entered complex number in the display. If the values displayed are the desired ones the user simply presses R/S to accept those values and continues on. Thus, the user can rerun the previously entered problem, say, because of a suspicion that some data may have been entered incorrectly.
User Instructions
1. Press XEQ L to start the program.
2. The display will flash "1.01" to request the complex coefficient from the first row and first column of the augmented matrix and stop with previously entered data in the display. Press R/S to accept the displayed data. To enter a new complex coefficient enter the imaginary part, press ENTER, enter the real part and press R/S.
3. The display will flash "1.02" to request the complex coefficient from the first row and second column of the augmented matrix, and so on. When the display flashes "1.04" enter the complex coefficient from the first row and fourth column of the augmented matrix, which is the first element of the vector.
4. Continue to enter the remaining coefficients in response to the prompts. If you fail to see a prompt you can recover it by pressing Roll Down.
5. When you press R/S after entering the data required in response to the prompt "3.04" the program will proceed with the solution. If the determinant of the input matrix is zero program execution will stop with the message "DIVIDE BY ZERO" in the display.
6. If the determinant of the input matrix is not zero the program willl stop with the determinant of the matrix in the display as x + iy and also in variables Y and Z. The augmented matrix will be in its original position in variables A through X. The solution vector will be in the six statistics registers.
7. Press R/S to see the first element of the solution vector.
8. Press R/S to see the second element of the solution vector.
9. Press R/S to see the third element of the solution vector.
10. The solution values can be recalled for further use with RCL (i) commands with i from 28 through 33 or more simply through use of the options of the SUMS menu as illustrated in program steps M088 through M0096
Program Listing
L0001 LBL L L0002 CF 4 L0003 1.024 L0004 STO i L0005 CL Sum L0006 1.01 L0007 Sum+ M0001 LBL M M0002 FIX 2 M0003 RADIX, M0004 Sumx From the SUMS menu M0005 ENTER M0006 PSE M0007 FIX 9 M0008 RADIX. M0009 RCL (i) M0010 1 M0011 STO+ i M0012 RD Roll Down M0013 RCL (i) M0014 STOP M0015 STO (i) M0016 1 M0017 STO- i M0018 RD M0019 x<>y M0020 FS? 4 M0021 0 M0022 STO (i) M0023 2 M0024 STO+ i M0025 0.01 M0026 Sum+ M0027 0.05 M0028 Sumx From the SUMS menu M0029 FP M0030 x ne y? Is x not equal to y ? M0031 GTO M M0032 0.96 M0033 Sum+ M0034 1 M0035 STO- i M0036 ISG i M0037 GTO M M0038 XEQ D M0039 29 M0040 STO i M0041 RD M0042 STO (i) M0043 DSE i M0044 x<>y M0045 STO (i) M0046 CMPLX 1/x M0047 XEQ V M0048 XEQ D M0049 33 M0050 STO i M0051 RD M0052 n From the SUMS menu M0053 Sumx From the SUMS menu M0054 CMPLX / M0055 STO (i) M0056 DSE i M0057 x<>y M0058 STO (i) M0059 XEQ V M0060 XEQ D M0061 31 M0062 STO i M0063 RD M0064 n From the SUMS menu M0065 Sumx From the SUMS menu M0066 CMPLX / M0067 +/- M0068 STO (i) M0069 DSE i M0070 x<>y M0071 +/- M0072 STO (i) M0073 XEQ V M0074 XEQ D M0075 29 M0076 STO i M0077 RD M0078 n From the SUMS menu M0079 Sumx From the SUMS menu M0080 CMPLX / M0081 STO (i) M0082 DSE i M0083 x<>y M0084 STO (i) M0085 XEQ V M0086 XEQ D M0087 STOP M0088 n From the SUMS menu M0089 Sumx From the SUMS menu M0090 STOP M0091 Sumy From the SUMS menu M0092 Sum x^2 From the SUMS menu M0093 STOP M0094 Sum y^2 From the SUMS menu M0095 Sum xy From the SUMS menu M0096 STOPTest problem:D0001 LBL D D0002 RCL A D0003 RCL B D0004 RCL K D0005 RCL L D0006 CMPLXx D0007 RCL U D0008 RCL V D0009 CMPLXx D0010 STO Z D0011 x<>y D0012 STO Y D0013 RCL C D0014 RCL D D0015 RCL M D0016 RCL N D0017 CMPLXx D0018 RCL Q D0019 RCL R D0020 CMPLXx D0021 STO+ Z D0022 x<>y D0023 STO+ Y D0024 RCL E D0025 RCL F D0026 RCL S D0027 RCL T D0028 CMPLXx D0029 RCL I D0030 RCL J D0031 CMPLXx D0032 STO+ Z D0033 x<>y D0034 STO+ Y D0035 RCL E D0036 RCL F D0037 RCL K D0038 RCL L D0039 CMPLXx D0040 RCL Q D0041 RCL R D0042 CMPLXx D0043 STO- Z D0044 x<>y D0045 STO- Y D0046 RCL A D0047 RCL B D0048 RCL S D0049 RCL T D0050 CMPLXx D0051 RCL M D0052 RCL N D0053 CMPLXx D0054 STO- Z D0055 x<>y D0056 STO- Y D0057 RCL C D0058 RCL D D0059 RCL I D0060 RCL J D0061 CMPLXx D0062 RCL U D0063 RCL V D0064 CMPLXx D0065 STO- Z D0066 x<>y D0067 STO- Y D0068 RCL Y D0069 RCL Z D0070 RTN
V0001 LBL V V0002 1.03002 V0003 STO i V0004 RCL G V0005 XEQ X V0006 5 V0007 STO- i V0008 RCL H V0009 XEQ X V0010 1 V0011 STO+ i V0012 RCL O V0013 XEQ X V0014 5 V0015 STO- i V0016 RCL P V0017 XEQ X V0018 1 V0019 STO+ i V0020 RCL W V0021 XEQ X V0022 5 V0023 STO- i V0024 RCL X V0025 XEQ X V0026 RTN
X0001 LBL X X0002 x<> (i) X0003 ISG i X0004 x<> (i) X0005 ISG i X0006 x<> (i) X0007 ISG i X0008 STO (i) X0009 RTN
The first number in each coefficient is the real part. The second number in each part is the imaginary part. But, remember that the imaginary part is entered first in the program.
+1,+3 -1,+2 +4, 0 +10,-8The determinant of the matrix is +155,-66 and the solution vector is-3,-2 -5,+1 +1,+1 +10,-4
+2, 0 0,+3 -3,+4 +25,+12
+3,+1To solve a linear equation with real coefficients:-2,-2
+1,-4
The primary purpose for this program is the solution of third order linear equations with complex coefficients. The program can be used to solve third order linear equations with real coefficients by simply entering a zero for each imaginary part during input. The FS? 4 0 sequence at M0020/M0021 provides an easier method of operation when using real coefficients. When the program stops to receive the first input after the prompt "1.01" set flag 4 before proceeding with input. Then it is only necessary to enter the real value at each input point since with flag 4 set the program will provide the zero for the imaginary part of each input. Thus, if this program is on your machine there is no need to have a program such as that in Article 599. You get both capabilities at a cost of one additional label. Note that flag 4 is reset at the beginning of the program.
Edited: 26 June 2007, 9:47 a.m.