Complex matrices in programs
12-14-2014, 12:46 PM (This post was last modified: 12-14-2014 01:54 PM by Snorre.)
Post: #1
 Snorre Member Posts: 101 Joined: Dec 2013
Complex matrices in programs
Hello,

I want to define a constant complex matrix within a program. The program check is successful, but when running I get an "Insufficient memory" error.
Example:
Code:
BEGIN   LOCAL x,y,z;  // Three identical matrices:   x:=MAKEMAT((I,J),2,2);  // works, but not what I want   y:=([[1,1],[2,2]],[[1,2],[1,2]]);  // works, but harder to read   z:=[[(1,1),(1,2)],[(2,1),(2,2)]];  // wanted, but throws an error   ...

I've searched the forum for a related answer and consulted the handbook, without success.
BTW: It doesn't make a difference if complex numbers are represented as a+i*b or (a,b).

Is that a bug or did I miss something?
If this is intentional behaviour, what would be the right way to do it?

Greetings

[EDIT] P.S. I've done it now by defining the matrix as a list and convert it, e.g. list2mat({{(1,1),(1,2)},{(2,1),(2,2)}}).
12-14-2014, 09:22 PM
Post: #2
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
RE: Complex matrices in programs
I played around with this as well, and can confirm the "insufficient memory error," if one tries to define the complex matrix directly inside the PPL program.

The best bet appears to be using list2mat (as you have already found out), e.g.,

LOCAL z:={1+1*i, . . . };
. . .
list2mat(z,2);

works just fine.
12-14-2014, 10:19 PM
Post: #3
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
RE: Complex matrices in programs
By the way, did you try to define a complex matrix within a CAS program?

I get "Unmatch control word" error message.

Actually, I just discovered that I can't run any CAS programs any more, even the default template "new CAS program" without any alteration returns

program([],[],[0 0]).

Resetting the calc also doesn't help. Is this occurring because of the "insufficient memory message"?
12-14-2014, 10:36 PM (This post was last modified: 12-14-2014 10:36 PM by Han.)
Post: #4
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: Complex matrices in programs
(12-14-2014 10:19 PM)Helge Gabert Wrote:  By the way, did you try to define a complex matrix within a CAS program?

I get "Unmatch control word" error message.

Actually, I just discovered that I can't run any CAS programs any more, even the default template "new CAS program" without any alteration returns

program([],[],[0 0]).

Resetting the calc also doesn't help. Is this occurring because of the "insufficient memory message"?

I can confirm the behavior with complex matrices in a non-CAS program. For CAS programs, I tried:

Code:
#cas TEST():= BEGIN local l:=[[(1,2)],[(3,4)],[(5,6)]]; return l; END; #end

This program ran fine in Home and CAS view (Firmware 6940).

Regarding complex matrices -- the parser actually converts any matrix into a list combined with a ListToMat() command. However, it seems to choke on complex matrices. You can see this by creating the following program that does nothing but declare and initialize two variables: a real value and a matrix and then debug it.

Code:
EXPORT TEST2() BEGIN local a:=0; local l:=[[1,COS(a)],[4,5]]; END;

This only occurs for matrices that do not consist of purely real numbers (in this case "COS(a)" not a real number in syntax).

Graph 3D | QPI | SolveSys
12-14-2014, 11:11 PM
Post: #5
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
RE: Complex matrices in programs
I don't get that. My calc seems to be messed up.

I get (in CAS):

->LOCAL[l:=[[1+2*i [] ]:= [return l]
3+4*i
5+6*i]]

and in Home

program([],[],LOCAL[ [[1+2*i [] ]:=[0 [[1+2*i ])
3+4*i 3+4*i
5+6*i]] 5+6*i]]

I presume it is time to reinstall the firmware, but 6940 has been pulled.
12-14-2014, 11:56 PM
Post: #6
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: Complex matrices in programs
I don't think reflashing the firmware is necessary. You might try [On][Symb] and deleting the bad programs, followed by turning the calculator OFF and another [On][Symb] after turning it on.

Graph 3D | QPI | SolveSys
12-15-2014, 12:07 AM
Post: #7
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
RE: Complex matrices in programs
Thanks for the suggestions - - did all that, but it doesn't work.

Even creating a new CAS program from scratch without modifying

#cas
ABC():=
BEGIN
return 0;
END;
#end

returns in Home

program([],[],[0 0])

and in CAS

->[return 0]

Or maybe I'll just wait till the next firmware comes out . . .
12-15-2014, 12:59 AM
Post: #8
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: Complex matrices in programs
You can always reflash it by right-clicking on the calculator in the conn. kit and manually force a reflash. The firmware should presumably still be in the firmware folder unless you made modifications to it.

Another option is to press and hold [C][F][O] during the warmstart from using [On][Symb] to "format" your memory (doesn't affect firmware; just factory resets it). It's under #4.

Graph 3D | QPI | SolveSys
12-15-2014, 01:15 AM (This post was last modified: 12-15-2014 01:31 AM by Helge Gabert.)
Post: #9
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
RE: Complex matrices in programs
Thanks!!!

The firmware updates are on a different computer at another location - - I'll be there again in two weeks and can try then.

I'm trying #4 (flash utility) right now. Suboptions 1,2 or 3 (or all of them)? I did them all - - lost all my programs now (can restore, though) - - but still, running the CAS shell program returns program([],[],[0,0]) in Home, and ->[return 0] in CAS.
12-15-2014, 02:02 AM (This post was last modified: 12-15-2014 02:02 AM by Han.)
Post: #10
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: Complex matrices in programs
I tried running just an empty shell of a CAS program and got the same results. I would consider this a bug. Interesting, if you run the ABC() program with: ABC(0) then it runs "properly." I was expecting to get an argument count error, but even ABC(1,2,3) returns 0 (which means the code runs ok, but that it's completely ignoring argument count).

Graph 3D | QPI | SolveSys
12-15-2014, 03:17 AM
Post: #11
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
RE: Complex matrices in programs
Ah, now it works. Always run a CAS program with an argument (even if it is not needed). I don't get the "unmatch control word" error message anymore either.

#cas
ABC(k):=
BEGIN
LOCAL z:={1+1*i, . . . };
return list2mat(z,2);
END;
#end

Thanks for helping!
12-15-2014, 03:55 AM
Post: #12
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: Complex matrices in programs
Strange... now I can only replicate the behavior in Home view but not CAS view.

Graph 3D | QPI | SolveSys
12-15-2014, 04:10 AM
Post: #13
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
RE: Complex matrices in programs
Even with an argument? Or without? With an argument, I can run the CAS shell just fine (in both views). Without an argument, I get the underlying codes.
12-15-2014, 04:20 AM
Post: #14
 Han Senior Member Posts: 1,810 Joined: Dec 2013
RE: Complex matrices in programs
(12-15-2014 04:10 AM)Helge Gabert Wrote:  Even with an argument? Or without? With an argument, I can run the CAS shell just fine (in both views). Without an argument, I get the underlying codes.

Without the arguments, that is. In Home view, I get program([],[],[0,0]); but in CAS I simply get 0 when I type ABC(). I did download some stuff onto my calculator, though. Would you humor me and download something (a program or app) to your calculator and see if it still misbehaves running CAS shell programs w/out an argument?

Graph 3D | QPI | SolveSys
12-15-2014, 05:08 AM (This post was last modified: 12-15-2014 05:09 AM by Helge Gabert.)
Post: #15
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
RE: Complex matrices in programs