# Why cant I multiply two vectors together on sage cell?

Hello all. Sage noob here. My friend recently told me about sage and convinced me to give it a whirl. (My background is MATLAB).

I made an account, and went to sage cell for a quick run. I typed this in:

v = vector([3, 4]);
vC = v.column();
vC*v


I would like to simply get the outer product of those two vectors. However it errors out.

I would like to think that I am boneheading something here, because this is a legitimate operation. I have multiple tutorial/documentation tabs open but nothing really elucidating why/how this doesnt work.

Would appreciate any insight.

edit retag close merge delete

Sort by » oldest newest most voted

When multiplied to the right, a vector behaves like a column matrix, when multiplied to the left, a vector behaves like a row matrix. So your product is like multipliying a $2\times 1$ by another $2\times 1$ matrix, which is invalid.

So, if you want v to be understood as a row matrix, you have to convert it as follows:

sage: Matrix(v)
[3 4]


sage: vC * Matrix(v)
[ 9 12]
[12 16]


Note that you could work with matrices from the beginning:

sage: v = Matrix([[3, 4]]) ; v
[3 4]
sage: vC = v.transpose() ; vC
[3]
[4]
sage: vC * v
[ 9 12]
[12 16]

more

Thanks tmonteil, however I am more confused now. If I try v*vC it works just find, but vC*v doesnt work - why the discrepancy? That is, why does it complain about the 'type' of data structure in one case, but does not complain about it in the other? Another thing: I tried to multiply v with a matrix A. It seems that it 'knows' how to interpret v regardless of which side I put it around A. Yet it does not know how to interpret v with A is substituted for vC? Not complaining, just trying to understand how it thinks. Thanks.

( 2014-02-17 06:09:33 -0600 )edit

I updated the beginning of my answer to explain this. You can check that if vC is a 2*2 matrix, then both v*vC and vC*v make sense

( 2014-02-17 07:43:46 -0600 )edit

OK, I guess that makes sense... thanks!

( 2014-02-17 08:40:08 -0600 )edit

sage: v = vector([3, 4])
sage: vc = v.column()
sage: vr = v.row()
sage: vr * vc
[25]
sage: vc * vr
[ 9 12]
[12 16]

more

That makes sense slelievre, but I am still confused as to why I can use "v" by itself. Why can I do v*A if A was a 2x2 matrix without having to tell it that v is a row vector?

( 2014-02-17 08:33:55 -0600 )edit