two-dim arrays of matrices?



The easiest solution is probably Maxima's hasharrays, something like this:

Q[2,3] : matrix(...)
Q[234,-23] : matrix(...)

This solution is reasonably efficient, flexible, and works well for both
sparse and dense structures. The keys don't even need to be numerical, and
the entries do not need to be of the same type:

Q["this",x+3] : {2.34,1/x,"John"}

The main restriction is that the number of subscripts of QQ must remain
consistent.  Note also that if you want a hasharray to be local to a block,
you will need to use "local".

You could also use a matrix of matrices, or a list of lists of matrices:

R : matrix( [ M1, M2 ], [M3, M4] )   << where Mx are themselves matrices
S : [ [ M1, M2] , [M3, M4] ]

It is generally a bad idea to generate names which include indices within
them (e.g. by concat('x,3,4) ).

Maxima is a Lisp-like language -- *everything* is actually a pointer
internally.  But Maxima intentionally limits what you can do with pointers.
 For example, though you can modify an *element *of a list, Maxima does not
let you modify the 'rest' (a.k.a. tail or cdr) of list.  Nonetheless, list
structure can be shared in some cases:

(%i1) l1: [a,b];
(%o1) [a,b]
(%i2) l2:[c,d];
(%o2) [c,d]
(%i3) l12: append(l1,l2);
(%o3) [a,b,c,d]
(%i4) l2[1]: 999;
(%o4) 999
(%i5) l12;
(%o5) [a,b,999,d]  << modifying l2 modified l12, because rest(l12,2) is the
same object as ('eq' in Lisp terms) l2

Another possibility is to use native arrays, but that is messier and
probably unnecessary in your case.  I'd recommend you stick with hasharrays.

Then again, you haven't told us what you're really trying to do, so I may
be answering the wrong question entirely.

           -s



On Fri, Jul 12, 2013 at 2:17 AM, Yury Tarasievich <
yury.tarasievich at gmail.com> wrote:

> Hello all,
>
> I need to put matrices into 2-dimensional array OR into some sort of
> structure having a pair of numerical keys.
>
> What is the best practice for that? I wouldn't want to loose efficiency
> using something anti-optimal.
>
> This might be an elementary question, but I'm absolutely new at Maxima,
> and I can't find what I need in docs or on the web, it seems.
>
> 1) I understand I might just generate names with "indices" at run time (by
> "evaluation" operation), but I'd prefer to use indexing with numbers.
>
> Also, is there an equivalent of C/C++ pointer/reference construct?
>
> 2) Or I might use 3- or 4-dimensional arrays but I don't know how to
> select a single matrix from such a structure (something like using C/C++
> A[i] selection from A[][] array).
> Also, will the result of such selection have the matrix type and be
> operable as one?
>
> Are these approaches equivalent in efficiency?
>
> -Yury
>
>
>
>
>
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>