Post Reply 
Blockmatrix
09-26-2016, 07:27 AM (This post was last modified: 10-09-2016 02:18 AM by toshk.)
Post: #1
Blockmatrix
Blockmat(2,3, {A,B,C,D,E,F})--> [A B C; D E F]
Blockmat(3,2, {A,B,C,D,E,F})--> [A B; C D; E F]
Blockmat(1,6, {A,B,C,D,E,F})--> [A B C D E F]
A, B, C, D, E, F are matrices of equal dimensions.
Code:

#cas
Blockmat(n,p,lst):=
BEGIN
local j,k,c,d,m3,m2;
IF ((n*p)<>size(lst)) THEN RETURN("matrices sizes"); END
m2:=[]; m3:=[]; L0:={};
if p==1 then Blockmat1();return(m2); end;
for k from 1 to n do
IF k==1 THEN 
for j from 1 to p do
L0(j):=lst(j);
end;
m2:=trn(concat(L0));
c:=p; 
ELSE
L0:={};
d:=1;
for j from c+1 to k*p do
L0(d):=lst(j);
d:=d+1;
end;
c:=k*p;
m3:=trn(concat(L0));
m2:=concat(m2,m3);
END;
end;
return(trn(m2));
END;
#end


#cas
Blockmat1()
BEGIN
LOCAL j;
L0:={};
B:=0;
[A,B]:=DIM(lst(1));
for j from 1 to (size(lst)-1) do
IF (DIM((lst(j)))<>DIM((lst(j+1)))) THEN kill; END;
end;
for j from 1 to (size(lst)) do
L0:=concat(L0,mat2list(lst(j)));
end;
IF B==0 THEN m2:=(list2mat(L0,colDim(lst(1)))); ELSE m2:=(list2mat(L0,B)); END;
END;
#end
Find all posts by this user
Quote this message in a reply
09-26-2016, 04:33 PM
Post: #2
RE: Blockmatrix
Isn't there already a command that does this (list2mat)?

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
09-26-2016, 06:12 PM (This post was last modified: 09-26-2016 06:18 PM by toshk.)
Post: #3
RE: Blockmatrix
if matrix A= [1 2; 3 4] and B =[5 6; 7 8]
to block A and B into 2*1 is C=[A;B]=[1 2; 3 4;5 6;7 8]
list2mat will block it to C=[[A],[B]]=[[1 2; 3 4];[5 6; 7 8]] with extra brackets

if you have matrices A,B,C,D to be block into 2*2 matrix
A,B need to augmented, C ,D need to augmented---> CONCAT in hp prime
then the first has to stack on the later---> no STACK in hp prime;
that's what my code does...
Find all posts by this user
Quote this message in a reply
09-28-2016, 05:55 PM
Post: #4
RE: Blockmatrix
I see now; this little program is quite useful.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 




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