Creating matrices to do the desired operations on other matrices.
Here is the general principle.
To do any operation with the rows of a matrix
with
rows and
columns, we start with the identity matrix of size
,
eye(n)
(or
or just
if the
is understood) and do the desired operation to it. Then multiply the resulting matrix to
on the
left
.
If you wish to do a similar thing to the columns, then you work on the columns of a suitable identity matrix and multiply on the right .
For example : find the third row of a 5 X 5 matrix.
> ans[3]:=row(eye(5),3);
> M:=randmatrix(5,5,entries=rand(0..10));evalm(ans[3]&*M);
To find the sum of the first three rows, you can do:
> evalm(row(eye(5),1)&*M+row(eye(5),2)&*M+row(eye(5),3)&*M);
To rotate the entries of a row of 4 numbers
. We think of this as permuting the four columns.
> A:=eye(4);RA:=augment(col(A,2),col(A,3),col(A,4),col(A,1));
> evalm([x,y,z,w]&*RA);
>
Note the multiplication on the right! It is crucial to multiply on the correct side.
As an exercise, find matrices
such that for every 5 X 5 matrix
, we have that
gives the sum of all entries of
.
Why do you need two matrices to do the job
?