Extracting submatrices with an existing lis...



Thanks, it works perfectly! I started to learn Maxima last week and so I know 
only a part of useful functions, now I've learned how to use apply and cons. 
Thanks.
I found a way to do the job, even if in a less elegant and efficient 
way. The idea was to create a list of the element to extract, and then use 
addcol. The code is this:

/* Initial data */
M : matrix([1,2,3,4,5],
[6,7,8,9,10]);

/* Indices to be excluded */
j[1] : 2;
j[2] : 5;

m2 : 
matrix();
collist : makelist(i,i,1,matrix_size(M)[2]);
/* Now we delete the 
unwanted indices */
for i:1 thru n do
	collist : delete(j[i],collist);
/* Now 
we extract the remaining columns and we create the new matrix */
for i in 
collist do
	matrix2 : addcol(matrix2,col(m,i));

The number n in the loop is 
the dimension of the array j, that I already knew form an earlier loop. 

I 
know this is a bad code, this was my workaround, immediately replaced by 
Robert's code!
Thanks a lot.
Stefano


>----Messaggio originale----
>Da: robert.
dodier at gmail.com
>Data: 26/12/2008 16.57
>A: "ferriste at libero.it"
<ferriste at libero.it>
>Cc: <maxima at math.utexas.edu>
>Ogg: Re: [Maxima] 
Extracting submatrices with an existing list of indices
>
>On 12/26/08, 
ferriste at libero.it <ferriste at libero.it> wrote:
>
>>  j[1] : 2;
>>  j[2] : 5;
>>

>>  so there are two columns to delete, the
>>  2nd and the 5th.
>
>listarray
(a) => list of elements of the undeclared array a
>
>so in this case try:
>

>apply (submatrix, cons (M, listarray (j)));
>
>(apply(foo, ...) is a way to 
call foo with a constructed list of arguments.)
>
>Hope this helps,
>
>Robert 
Dodier
>