[42S] Test for COMPLEX matrix - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: [42S] Test for COMPLEX matrix (/thread-3465.html) |
[42S] Test for COMPLEX matrix - Werner - 03-23-2015 02:05 PM This must've come up before, I'm sure. Take the sequence: Code: COMPLEX If - like me - you're writing code that must run for real input as well as for complex, you test your input. But REAL? sadly only tests for real numbers, not matrices. So my question, or challenge if you want, is: Write a routine that will deliver the complex conjugate of a complex matrix, and will leave a real matrix alone. You cannot EDIT or INDEX the matrix, and you can use only two stack levels. In: Complex matrix Out: Complex conjugate matrix In: real matrix Out: matrix untouched. Anyone? Cheers, Werner I can do it, but it's not pretty. I hope I'm missing something. RE: [42S] Test for COMPLEX matrix - Gerson W. Barbosa - 03-23-2015 03:17 PM (03-23-2015 02:05 PM)Werner Wrote: But REAL? sadly only tests for real numbers, not matrices What about ENTER DOT then REAL? or COMPLEX? and LAST x for a copy of the original matrix? But DOT takes a while to process, especially for larger matrices, so this might not be a good idea... Cheers, Gerson. RE: [42S] Test for COMPLEX matrix - Werner - 03-23-2015 06:05 PM That's what I meant when I said it wasn't pretty... it's all I've been able to come up with as well. Werner RE: [42S] Test for COMPLEX matrix - J-F Garnier - 03-23-2015 07:44 PM (03-23-2015 02:05 PM)Werner Wrote: So my question, or challenge if you want, is: What about: SF 25 ABS FS?C 25 GTO 01 COMPLEX +/- COMPLEX RTN LBL 01 CLX LASTX RTN J-F RE: [42S] Test for COMPLEX matrix - Werner - 03-24-2015 07:12 AM Aha, ABS doesn't work on a complex matrix, I didn't know that. For an NxM matrix: ENTER DOT will perform N*M operations, in both real and complex cases. ABS will also perform N*M (simpler) operations AND create a new matrix, but only in the real case. So, better and worse. Werner RE: [42S] Test for COMPLEX matrix - Gjermund Skailand - 03-24-2015 06:36 PM Hi Werner This is not pretty either, but perhaps faster CF 00 X <> "REGS" STO ST L CLX RCL 00 CPX? SF 00 X <>L X <> "REGS" FS? 00 COMPLEX FS? 00 +/- FS?C 00 COMPLEX Can definately be improved... best regards Gjermund RE: [42S] Test for COMPLEX matrix - Werner - 03-24-2015 08:11 PM Like this? Remember you can use two stack levels Code: X<> "REGS" or this Code: X<> "REGS" Unfortunately, I'm afraid X<> "REGS" makes a copy of the matrix as well, at least I think it does. It doesn't work with a matrix that takes up slightly over half the available memory, it returns 'Insufficient Memory'. Still, I use it in cases where I need access to two matrices at a time. Cheers, Werner RE: [42S] Test for COMPLEX matrix - Gjermund Skailand - 03-25-2015 08:39 AM I see. Like your use og AON as a "free" flag. And it gives me an idea. How about using the complex matrix descriptor CLA ARCL ST X 67 POSA X>0? ... Best regards Gjermund RE: [42S] Test for COMPLEX matrix - Werner - 03-25-2015 10:42 AM Yes, that's it!! No speed penalty, no matrix duplication, and only 2 stack levels. I would never have thought of that, thanks Gjermund! Werner RE: [42S] Test for COMPLEX matrix - Gerald H - 03-25-2015 11:03 AM (03-25-2015 10:42 AM)Werner Wrote: Yes, that's it!! Yes, a very elegant solution. But you might have thought of it if you'd asked the question "How do I know it's a complex matrix?". RE: [42S] Test for COMPLEX matrix - Werner - 03-25-2015 03:54 PM No, I wasn't aware you could ARCL a matrix. BTW this may be the time and place to express my admiration for Free42: the excruciating detail in which it mimicks the true 42S is unbelievable. It even implements the hidden [MAX], [MIN] and [FIND] commands. And it also returns NO when trying CPX? on a complex matrix ;-) Fantastic job, Thomas Okken. Cheers, Werner RE: [42S] Test for COMPLEX matrix - Gjermund Skailand - 03-25-2015 06:42 PM The Free42 is really a fantastic piece of software. And running it on a smartphone is amazing. Solving a 1000 degree system is far outside the original design parameters, yet still it works and with high accuracy too! Sometimes I even contemplate putting my thrusty hp50g in a drawer. Brgds Gjermund RE: [42S] Test for COMPLEX matrix - Werner - 03-26-2015 12:27 PM So, for posterity, the CMAT? function: CMAT? returns 1 for a complex matrix, 0 for everything else. Code:
Cheers, Werner |