(12C) Complex Arithmetic
05-20-2017, 01:47 PM (This post was last modified: 05-20-2017 01:47 PM by Eddie W. Shore.)
Post: #1
 Eddie W. Shore Senior Member Posts: 737 Joined: Dec 2013
(12C) Complex Arithmetic
Let A and B represent the two complex numbers

A = R1 + R4*i
B = R2 + R5*i

Where i = √-1

Store real components in R1 and R2, and imaginary parts R4 and R5. Choose the arithmetic calculations:

Enter 0 for addition: A + B
Enter 1 for multiplication: A * B
Enter 2 or otherwise for division: A ÷ B

Result: C = R3 + R6*i

Program:
Code:
 STEP    CODE            KEY 01    44, 0            STO 0 02    43, 35    X=0 03    43, 33, 09    GTO 09  04    1             1 05    30             - 06    43, 35    X=0 07    43, 33, 18    GTO 18 08    43, 33, 35    GTO 35 09    45, 1            RCL 1 10    45, 2            RCL 2 11    40            + 12    44, 3            STO 3 13    45, 4            RCL 4 14    45, 5            RCL 5 15    40            + 16    44, 6            RCL 6 17    43, 33, 63    GTO 63 18    45, 1            RCL 1 19    45, 2            RCL 2 20    20            * 21    45, 4            RCL 4 22    45, 5            RCL 5 23    20            * 24    30            - 25    44, 3           STO 3 26    45, 1           RCL 1 27    45, 5           RCL 5 28    20           * 29    45, 2          RCL 2 30    45, 4          RCL 4 31    20         * 32    40         + 33    44, 6         STO 6 34    43, 33, 63    GTO 63 35    45, 2         RCL 2 36    36         ENTER 37    20         * 38    45, 5         RCL 5 39    36         ENTER 40    20         * 41    40         + 42    44, 0         STO 0 43    45, 1         RCL 1 44    45, 2         RCL 2 45    20         * 46    45, 4         RCL 4 47    45, 5         RCL 5 48    20         * 49    40         + 50    45, 0         RCL 0 51    10         ÷  52    44, 3         STO 3 53    45, 4         RCL 4 54    45, 2         RCL 2 55    20         * 56    45, 1         RCL 1 57    45, 5         RCL 5 58    20         * 59    30         - 60    45, 0      RCL 0 61    10        ÷  62    44, 6        STO 6 63    45, 3        RCL 3 64    31        R/S 65    45, 6        RCL 6 66    43, 33, 00    GTO 00

Example:
A = 4.25 + 3.16*i, B = -2.27 + 1.04*i

Option 0 (+): 1.98 + 4.20*i
Option 1 (*): -12.93 – 2.75*i
Option 2 (÷): -1.02 – 1.86*i
05-24-2017, 05:27 PM
Post: #2
 hibiki Junior Member Posts: 21 Joined: Sep 2016
RE: (12C) Complex Arithmetic
Hi Eddie ! Nice program.

In step 16, there is a mistake: you wrote "RCL"6 instead of "STO"6. The keycode is correct.

My calcs: HP12C, HP15C, HP17BII+, HP20S, HP20B, HP32SII, HP34C, HP35S, HP42S, HP48GX.
05-27-2017, 09:02 AM (This post was last modified: 05-27-2017 09:20 AM by Dieter.)
Post: #3
 Dieter Senior Member Posts: 2,174 Joined: Dec 2013
RE: (12C) Complex Arithmetic
(05-20-2017 01:47 PM)Eddie W. Shore Wrote:  Store real components in R1 and R2, and imaginary parts R4 and R5. Choose the arithmetic calculations:

This approach can be improved so that you do not have to store four values into four registers. The program may do this for you. Also chain calculations are possible if the final result is stored as input for the next calculation.

Here is my suggestion:

Code:
01-    44 2   STO 2 02-      34   X<>Y 03-    44 1   STO 1 04-    45 1   RCL 1     ' display first operand 05-    45 2   RCL 2     ' resp. result of last calculation 06-      31   R/S       ' and wait for another operand & opcode 07-      33   R↓ 08-    44 4   STO 4 09-      33   R↓ 10-    44 3   STO 3 11-      33   R↓ 12-      33   R↓ 13-       1   1 14-      30   - 15-   43 35   X=0?      ' code=1 ? 16-43,33 31   GTO 31    ' jump to add routine 17-       1   1 18-      30   - 19-   43 35   X=0?      ' code=2 ? 20-43,33 36   GTO 36    ' jump to subtract routine 21-       1   1 22-      30   - 23-   43 35   X=0?      ' code=3 ? 24-43,33 51   GTO 51    ' jump to multiply routine 25-       1   1 26-      30   - 27-   43 35   X=0?      ' code=4 ? 28-43,33 41   GTO 41    ' jump to divide routine 29-       0   0 30-      10   /         ' else generate Error 0 31-    45 3   RCL 3     ' addition 32- 44 40 1   STO+ 1 33-    45 4   RCL 4 34- 44 40 2   STO+ 2 35-43,33 04   GTO 04 36-    45 3   RCL 3     ' subtraction 37- 44 30 1   STO- 1 38-    45 4   RCL 4 39- 44 30 2   STO- 2 40-43,33 04   GTO 04 41-    45 3   RCL 3     ' division 42-      36   ENTER 43-      20   * 44-    45 4   RCL 4 45-      36   CHS 46-    44 4   STO 4 47-      36   ENTER 48-      20   * 49-      40   + 50-43,33 52   GTO 52 51-       1   1         ' multiplication 52-    44 0   STO 0     ' common code for multiply and divide starts here 53-    45 1   RCL 1 54-    45 3   RCL 3 55-      20   * 56-    45 2   RCL 2 57-    45 4   RCL 4 58-      20   * 59-      30   - 60-    45 2   RCL 1 61-    45 4   RCL 4 62-      20   * 63-    45 3   RCL 3 64-    45 2   RCL 2 65-      20   * 66-      40   + 67-    44 2   STO 2 68-      34   X<>Y 69-    44 1   STO 1 70-    45 0   RCL 0 71- 44 10 1   STO/ 1 72- 44 10 2   STO/ 2 73-43,33 04   GTO 04

Enter program, switch back to run mode [P/R]

0. Reset calculation:  [f] [PRGM]
1. Enter first operand:  real [ENTER] imaginary part [R/S]
2. Enter second operand and opcode:  real [ENTER] imaginary part [ENTER] code [R/S]
where code=1 for add, 2 for subtract, 3 for multiply and 4 for divide.
Any other code yields Error 0.

For further calculations with the result continue with step 2.

Example: (3+4i * 5–6i) / (1+2i) + (7+3i)

Code:
[f] [PRGM] 3 [ENTER] 4 [R/S]                    4,00 5 [ENTER] 6 [CHS] [ENTER] 3 [R/S]    2,00 [X<>Y] 39,00   ' = 39 + 2i 1 [ENTER] 2 [ENTER] 4 [R/S]        -15,20 [X<>Y]  8,60   ' = 8,6 - 15,2i 7 [ENTER] 3 [ENTER] 1 [R/S]        -12,20 [X<>Y] 15,60   ' = 15,6 - 12,2i

So the final result is 15,6 – 12,2 i

Of course the intermediate results do not have to be examined by [X<>Y] to show the real part, you can simply continue calculating after each step.
Start a new calculation with [f][PRGM] which resets the program to step 00 to accept a new first operand.

Dieter
06-27-2017, 10:17 PM
Post: #4
 bshoring Member Posts: 236 Joined: Dec 2013
RE: (12C) Complex Arithmetic
I like Dieter's approach the best. It allows chain calculations and is more flexible.

Regards,
Bob
 « Next Oldest | Next Newest »

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