Reputation: 75
I want to multiply matrix M to vector V. Should be a vector. I write
M:matrix([a,b,c],[d,e,f],[g,h,r]);
V:[w,k,t];
res:M.V;
I get the column-matrix.
I want to get list [a*w+c*t+b*k,d*w+f*t+e*k,g*w+r*t+h*k]
.
OK. I have to write res:[res[1][1],res[2][1],res[3][1]];
How to do it more efficiently?
Upvotes: 1
Views: 2587
Reputation: 810
Just adding this, for completeness, in case anyone else has the same question.
First, I believe V
, as defined in the OP, is actually a list
and not a vector
, by Maxima's definitions; however, the approach is the same, in either case:
M:matrix([a,b,c],[d,e,f],[g,h,r]);
V:[w,k,t]; /* V is a list */
v1:transpose([w,k,t]); /* v1 is a column vector */
v2:matrix([w],[k],[t]); /* v2 is a column vector */
In all cases, use args
:
output1:args(M.V); /* returns a list of lists */
output2:args(M.v1); /* returns a row vector */
output3:args(M.v2); /* returns a row vector */
will return objects that look the same, but don't have exactly the same behaviour. For example:
output1[1,1]; /* will return an error, because `output1` is a list, not a matrix */
output1[1][1]; /* will return the first (only) entry of the first list */
output2[1,1]; /* returns the 1-1 element of the vector `output2` */
output2[1][1]; /* isn't defined, because `output2` is a vector, not a list */
(and similarly for output3).
Upvotes: 0
Reputation: 11
This function returns the i-th column of a matrix similar to Matlabs M(:,i)
col(M,i) :=
block(
return(transpose(transpose(M)[i]))
)$
This function returns the i-th row of a matrix similar to Matlabs M(i,:)
row(M,i) :=
block(
return(transpose(transpose(M[i])))
)$
Upvotes: 1