HP15C strange complex number behavior



#3

I have a program to add n complex numbers, stored as magnitude and phase in the columns of an n x 2 matrix. It converts them one at a time to rectangular format and adds them to the stored sum. I'm setting register I based on the matrix dimension and using ISG to end the loop.

In each case, on the last step of the loop, the "I" key to move the value to the imaginary location fails. It doesn't do this if I perform all the calculations manually, only with the program, and only on the last row of the matrix. The problem seems independent of the matrix size. The sum is correct if I force the program to terminate on the next-to-last row rather than the last row of the matrix.

Here is the program, programmed and run in user mode. This is my first post, so I apologize if it doesn't conform to the nomenclature usually used here.

LBL E
RCL DIM A "Get the matrix dimensions"
X <> Y "Move the number of rows into X"
.
0
0
1
* "Multiply by .001 to set the loop counter
1
+
STO I "Add 1 and store the loop counter as 1.00n in Reg I"
MATRIX 1 "Move to beginning of matrix"
0
ENTER "Initialize the sum"
LBL 1 "Start of loop"
RCL A "Recall magnitude from first column of matrix"
RCL A "Recall phase from second column"
I "Move into imaginary part of X"
-> R "Convert to rectangular"
+ "Add to sum"
ISG I "Check counter for loop end"
GTO 1 "Loop"
-> P "Convert sum to polar form when finished"
RTN

To run the program, dimension the A matrix and load the complex numbers into it, then press "E" in user mode to execute the program. On the last row, it fails to move the second column into the imaginary part of x, instead adding it as a real number to the real part of x.

Anyone know what's going on here? This happens on my HP15C LE and on my DM-15CC. Haven't tried it yet on my original HP15C.

If I replace the 1 in the 9th instruction with 2, so that 2.00n is loaded into reg I and the loop terminates before reaching the last row of the matrix, the sum of the first n-1 rows is correct.

Mike


#4

The second "RCL A" is skipping the next instruction when it hits the end of the matrix. When programmed in user mode, RCL and STO when applied to a matrix not only updates the row/column indices but skips the next instruction when running off the end of the matrix (sort of like ISG/DSE when hitting the end of a loop).


#5

Quote:
The second "RCL A" is skipping the next instruction when it hits the end of the matrix. When programmed in user mode, RCL and STO when applied to a matrix not only updates the row/column indices but skips the next instruction when running off the end of the matrix (sort of like ISG/DSE when hitting the end of a loop).

Excellent information! Thanks!

Was this documented somewhere I missed?

I'll have to see if I can rewrite this to automatically detect the end of the matrix and eliminate querying the dimension at the beginning of the routine.

Mike


#6

Hi.

The very first attempt on making it work is to add a 'ghost' label - an unused label - after the second RCL A. This way, whether it is 'wrapping' the matrix - i.e. jumping from the las element to the first one - or in the middle of it, the ghost label will be either skipped or 'executed', and in each case it will not disturb program execution. All you'll have is a bit slower execution for each time the 'ghost' label is found it will be 'executed'.

Make sure this label is not used elsewhere, or else it will be reached when not needed.

About the RCL/STO behavior in user mode: try p. 176 under 'Using Matrix Operation in a Program' and p. 177 (my HP15C manual is 00015-90001 Rev. E, February 1982), the first diagram, and you'll see the reference for using USER RCL/STO in a program. Also, p.144, last paragraph before the Example, bottom of the page:

Quote:
After the last element of the matrix has been accessed, the row and column numbers both return to 1.
In the HP15C LE manual you'll find it at the very same page.

One small trick: replace

.
0
0
1
×
to
EEX
3
÷ (divide)
and you'll save two bytes with the same operation. 8^)

Cheers.

Luiz (Brazil)


Edited: 11 Sept 2012, 12:43 a.m.

#7

Please, check if this listing works the same:

LBL E
MATRIX 1 "Move to beginning of matrix"
0
ENTER
ENTER "Initialize the sum"
LBL 1 "Start of loop"
I "Move into imaginary part of X"
-> R "Convert to rectangular"
+ "Add to sum"
RCL A "Recall magnitude from first column of matrix"
RCL A "Recall phase from second column"
GTO 1 "Loop"
I "if end of matrix, GTO 1 is skipped and program continues here"
->R "repeats the three steps for adding last vector (unfortunately needed)
+
-> P "Convert sum to polar form when finished"
RTN
It is shorter because it does not use register [I], only the skipping feature after the last element is reached. I needed to repeat the three steps for adding the last vector, which is not elegant, but this listing is still 7 steps shorter. Note that I did not check it by running it, chances are it will not work.

Cheers.

Luiz (Brazil)

Edited: 11 Sept 2012, 12:44 a.m.


#8

Quote:
Please, check if this listing works the same:
LBL E
MATRIX 1 "Move to beginning of matrix"
0
ENTER
ENTER "Initialize the sum"
LBL 1 "Start of loop"
I "Move into imaginary part of X"
-> R "Convert to rectangular"
+ "Add to sum"
RCL A "Recall magnitude from first column of matrix"
RCL A "Recall phase from second column"
GTO 1 "Loop"
I "if end of matrix, GTO 1 is skipped and program continues here"
->R "repeats the three steps for adding last vector (unfortunately needed)
+
-> P "Convert sum to polar form when finished"
RTN
It is shorter because it does not use register [I], only the skipping feature after the last element is reached. I needed to repeat the three steps for adding the last vector, which is not elegant, but this listing is still 7 steps shorter. Note that I did not check it by running it, chances are it will not work.

Cheers.

Luiz (Brazil)



Worked like a charm. Thanks, Luiz.

Mike


Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange HP 25 Problem (Repair) Onur Ilkorur 5 2,926 12-06-2013, 05:13 PM
Last Post: Onur Ilkorur
  HP Prime: complex numbers in CAS. Alberto Candel 1 1,924 12-06-2013, 02:36 PM
Last Post: parisse
  Strange Battery Icon during updaate of Prime Firmware. Harold A Climer 7 3,546 12-05-2013, 04:40 PM
Last Post: Michael de Estrada
  [HP Prime] Plots containing complex numbers bug? Chris Pem10 7 3,666 12-05-2013, 07:40 AM
Last Post: cyrille de Brébisson
  Complex Number Entry on Prime Jeff O. 19 5,198 11-16-2013, 12:34 PM
Last Post: Jeff O.
  HP PRIME : strange behavior when trying user key capability Damien 12 3,975 11-03-2013, 11:02 AM
Last Post: Joe Horn
  1984 HP15C rattles Footloose (Illinois) 4 1,934 10-15-2013, 09:43 PM
Last Post: BobVA
  HP Prime complex results Javier Goizueta 0 996 10-06-2013, 12:59 PM
Last Post: Javier Goizueta
  HP Prime function APP - Strange limitation ! :o( dg1969 2 1,614 10-04-2013, 12:10 PM
Last Post: dg1969
  HP15c continued fraction for Ln(Gamma) Tom Grydeland 0 1,123 09-30-2013, 05:48 AM
Last Post: Tom Grydeland

Forum Jump: