nm

8552 Reputation

19 Badges

13 years, 27 days

MaplePrimes Activity


These are questions asked by nm

Maple 16:

Given Matrix A of size nRow,nCol, and a vector b of size nCol, I wanted to divide each value in column 
K by b(K) where k=1..nCol and the result will be a matrix B also of size nRow,nCol ofcourse.

For example, I want to do A[..,1]/b[1],  A[..,2]/b[2], etc.. for each column of A

The way I do it now is by using seq(), then convert the result to matrix, like this:


nCol := LinearAlgebra:-ColumnDimension(A):
B    := convert([seq(A[..,i]/b[i],i=1..nCol)],Matrix);

And it works.  But was wondering if there is a better way to do this. I tried to use apply map but did 
not know how to
Here is below the complete Maple 16 code I have:

------------------------
A := LinearAlgebra:-RandomMatrix(3,4);
b := MTM:-sum(A,1);
nCol := LinearAlgebra:-ColumnDimension(A):
B := convert([seq(A[..,i]/b[i],i=1..nCol)],Matrix);
MTM:-sum(B,1);  #verify the sum is 1

First 162 163 164 Page 164 of 164