Reputation: 157
In Maxima I want to define vectors using the columns of randomly generated matrix where not only the entries but also the number of rows and columns is random. My code so far:
n:2+random(5);
m:2+random(5);
h[i,j]:=5-random(11);
M:genmatrix(h,n,m);
The number of rows/colums can ranges from 2 to 6 (not neccesarily n=m) and the entries are random integers from -5 to 5.
I can now use
v1:col(M,1);
to define the vector v1 as the first column of the matrix M, but since I don't know how many columns there are I tried this:
for i thru n do (vi:col(Mt,i));
This returns "Done" but when I enter
v1;
I just get "v1" as the result and not the first column of the matrix. With
for i thru n do (disp (v[i]=col(Mt,i)));
I can get Maxima to display all the columns as vectors but again I get just "v1" as the result. Can anyone tell me what I am doing wrong?
Upvotes: 0
Views: 1140
Reputation: 17576
I can't test this code right now but I believe this or something pretty similar should work.
Here is a way to generate a random matrix and then extract the columns of the matrix. I don't know if you want to present the columns as column vectors or as row vectors. Maxima doesn't really have a way to represent row and column vectors as distinct types. Instead for a column vector, I'll obtain a matrix of 1 column, and for a row vector, I'll obtain a list.
[m, n]: [2 + random(5), 2 + random(5)];
h: lambda ([i, j], random(11) - 5) $
M: genmatrix (h, m, n);
Here is a list comprising the columns of M as 1-column matrices:
makelist (col (M, k), k, 1, n);
Here is a list comprising the columns of M as lists:
args (transpose (M));
Upvotes: 2