Problem with Matrix



On Thursday 18 December 2008 10:24:55 Rene Grothmann wrote:
> I am trying to make some student functions for differentiation,
> such as gradient, Jordan matrix, Hesse matrix. However, I have
> troubles handling matrices.
>
> 1) Is there a way to ask the dimensions of a matrix?

length(A) gives the number of rows in A. A[k] is the k'th row in A:

  (%i1) A : zeromatrix(3,4)$
  (%i2) length(A);
  (%o2) 3
  (%i3) length(A[1]);
  (%o3) 4
  (%i4) length(transpose(A));
  (%o4) 4

> 2) Is genmatrix the right way to go, like in
>
> gradient(expr,var) :=
> genmatrix(lambda([i,j],diff(expr,var[j])),1,n)
>
> where n is the length of var?

Yes.

> 3) Is there any difference between a vector [x,y] and a 1x2-matrix?

Yes. Actually, [x_1,...,x_n] is a list. But when listarith is true, 
list-matrix operations treat [x_1,...,x_n] as an 1xn matrix.

  (%i01) matrixp([1,2,3]);
  (%o01) false
  (%i02) listp([1,2,3]);
  (%o02) true
  (%i03) transpose([1,2,3]);
  (%o03) matrix([1],[2],[3])
  (%i04) [1,2,3] . transpose([1,2,3]);
  (%o04) 14
  (%i05) transpose([1,2,3]) . [1,2,3];
  (%o05) matrix([1,2,3],[2,4,6],[3,6,9]);
  (%i06) listarith : false;
  (%o06) false
  (%i07) [1,2,3] . transpose([1,2,3]);
  (%o07) [1,2,3] . matrix([1],[2],[3])
  (%i08) transpose([1,2,3]) . [1,2,3];
  (%o08) matrix([1],[2],[3]) . [1,2,3]

There are some other option variables for matrix / scalar-matrix / 
list-matrix operations; see the corresponding section in the Maxima 
Manual.

-- 
Boomtime, Aftermath 60 YOLD 3174
Alexey Beshenov  http://beshenov.ru/