Post Reply 
Struggling with CAS programming
09-17-2018, 09:57 PM
Post: #7
RE: Struggling with CAS programming
(09-17-2018 03:45 AM)rushfan Wrote:  
(09-17-2018 03:27 AM)Didier Lachieze Wrote:  Two things :
  1. I've found you need to declare your local variables before assigning them
  2. the line a(lpv,lpv+1) = 1; should be replaced by a[lpv,lpv+1]:=1;

Code:
#cas
tf2ss(num,den):=
BEGIN
// declare vars and allocate matrices
local ordem,a,b,c,d;
ordem := size(den)-1;
a:= identity(ordem)*0;
b:= identity(ordem)*0;
c:= revlist(num);
d:=0;
// fill A is in the form [0 1 0; 0 0 1; -p/m -o/m -n/m], where n m o p are from den
a:= replace(a,{ordem,1},-revlist(den[2..(ordem+1)])/den(1));
FOR lpv FROM 1 TO ordem-1 DO
a[lpv,lpv+1]:=1;
end;
// fill b 
b:= delrows(b,2..ordem);
b:= replace(b,{1,ordem},[1]);
b:= tranpose(b);

return a;
return b;
return c;
return d;
END;
#end

The code still does not work, even with the changes proposed. It gives "Error: Unmatch control word"

You seem to have noticed that a function returns only one value
because your last version combined the RETURNs into a list.

LOCAL d:=0; // is allowed since a simple value can be assigned in a variable declaration
but the code is more clear the way you do it.

Note that you didn't declare the FOR lpv
I remember once having code where I needed even FOR variable declaration.
VPN
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Struggling with CAS programming - rushfan - 09-17-2018, 12:54 AM
RE: Struggling with CAS programming - CyberAngel - 09-17-2018 09:57 PM



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