Size of a matrix



These functions which Stavros uses provide the correct answer, faster
and with less consing then my answer.  However, I want to point out
some other issues. First, the reason that I used
length(transpose(row(m,1)))
is that length(row(m,1)) is 1.  This is not a useful result.  Also if
length is defined as the
number of columns of a matrix, then length of a row should be the number
of elements in the row.  Length applied to a matrix should either return
a list of 2 elements, or throw a exception.  The reason it returns the
number of columns is implementation dependent, from representing
matrices as lists anyway.

It is also inconsistant with
m: matrix([a,b,c],[d,e,f])$
op(m) => matrix
a:args(m) => [ [a,b,c], [d,e,f] ], where
length(a)=>2, and length(first(a))=> 3
which I am somewhat more comfortable with, as it is not implementation
dependent.

Now, what about a matrix with N columns and zero rows, should it be
possible to define this?
Or its transpose?
Dan Stanger

Stavros Macrakis wrote:

> > Is there a way to determine the size (number of rows, number of
> > columns) of a matrix in Maxima?
>
> Number of columns: length(m)
> Number of rows: length(m[1])
>
> Explanation:
>
> m: matrix([a,b,c],[d,e,f])$
> op(m) => matrix
> args(m) => [ [a,b,c], [d,e,f] ]
> length(args(m)) == length(m) => 2
> m[1] => [a,b,c]
>   (Note that this is NOT the same as row(m,1) =>
>    matrix([a,b,c]), a matrix containing one row.)
> length(m[1]) => 3
>   (In a matrix, all rows are guaranteed to be the
>    same length.)
>
> _______________________________________________
> Maxima mailing list
> Maxima@www.math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima