Numerical Matrix operations



On Wed, Jun 11, 2008 at 8:11 AM, Kun Lin <klin at umd.edu> wrote:

> 2) When I declear a matrix of either 1xn or nx1. Let's call that matrix
> M.  so in matlab, i can just think of M as a vector.
> Meaning it doesn't matter if the matrix is 1xn or nx1 when i do M[2] it
> will return the same element.


What do you mean by "declare" here?

In Maxima, M[i] means the i'th row of a matrix:

    m: matrix([a,b],[c,d])$
    m[1] => [a,b]
    m[2] => [c,d]

What would your m[2] operator do with matrix m?


>  However, in maxima i have to explicitly do
> either M[2,1] or M[1,2] depending on the dimension of the matrix.  Is
> there a way for maxima to do what matlab is doing?
>

Perhaps something like:
  vectori(v,i) :=
  if listp(v) then v[i]
  elseif matrixp(v) and length(v)=1 then v[1,i]
  elseif matrixp(v) and length(v[1])=1 then v[i,1]
  else error("vectori takes a list, 1xn, or nx1 matrix argument",v)$

Note that Maxima often allows lists to be used as 1x or x1 matrices.


> 3) When i call row(M,1), maxima returns a matrix back. can i make it so
> that it returns an array?
>

No, arrays are a different thing entirely and are not first-class objects in
Maxima.  If you want a *list*, you can use simply M[1].

Why do you want to use arrays?


> 5) Can i do object oriented programming in maxima? (creating classes)
>

There is no explicit support for object-oriented programming in Maxima, but
there are various ways to fake it, since functions are first-class objects.

            -s