Blockmatrix
09-26-2016, 07:27 AM (This post was last modified: 10-09-2016 02:18 AM by toshk.)
Post: #1
 toshk Member Posts: 189 Joined: Feb 2015
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
 « Next Oldest | Next Newest »

 Messages In This Thread Blockmatrix - toshk - 09-26-2016 07:27 AM RE: Blockmatrix - Han - 09-26-2016, 04:33 PM RE: Blockmatrix - toshk - 09-26-2016, 06:12 PM RE: Blockmatrix - Han - 09-28-2016, 05:55 PM

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