Post Reply 
Programming Question: How do you augment one matrix with another?
07-05-2014, 06:31 PM (This post was last modified: 07-05-2014 06:59 PM by Jsather.)
Post: #17
RE: Programming Question: How do you augment one matrix with another?
(07-02-2014 06:09 AM)cyrille de brĂ©bisson Wrote:  REPLACE(M1, {r,c}, M2) will place M2 at a given location in M1

Now, back to your problem... I do not have an augment command, however, you can do:
M3:=MAKEMAT(0, r, c); REPLACE(M3,{1,1},M1); REPLACE(M3,{0,c}, M2);
3 commands, but no loops or the like...
Earlier I mentioned an apparent bug in Replace that prevented Cyrille's makemat; replace; replace; method from working. I now have an explanation: not a bug. Replace(M3,{1,1},M1) returns M3 with M1 inserted beginning at (r,c)=(1,1), but does not change M3. To make the example work, it needs to be M3:=Replace(M3,{1,1},M1). This is counterintuitive because "replace" leads us to an assumption of replacement in M3.

For vertical augmentation:
M3:=makemat(0,rowDim(M1)+rowDim(M2),colDim(M1));
M3:=replace(M3,{1,1},M1);
M3:=replace(M3,{rowDim(M1)+1,1},M2);
or
M3:=M1;
redim(M3,{rowDim(M1)+rowDim(M2),colDim(M1)});
M3:=replace(M3,{rowDim(M1)+1,1},M2);

For horizontal augmentation:
M3:=makemat(0,rowDim(M1),colDim(M1)+colDim(M2));
M3:=replace(M3,{1,1},M1);
M3:=replace(M3,{1,colDim(M1)+1},M2);
or
M3:=M1;
redim(M3,{rowDim(M1),colDim(M1)+colDim(M2)});
M3:=replace(M3,{1,colDim(M1)+1},M2);

These and the several other methods discussed in this thread could form the basis of a general purpose augmentation subroutine. The apparent absence of a matrix augment command is a surprising deficiency in the HP Prime command set.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming Question: How do you augment one matrix with another? - Jsather - 07-05-2014 06:31 PM



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