Ask Your Question

Why cant I multiply two vectors together on sage cell?

asked 2014-02-17 05:11:18 -0500

Gravitus gravatar image

updated 2014-02-17 05:30:09 -0500

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();

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-02-17 05:44:54 -0500

tmonteil gravatar image

updated 2014-02-17 07:47:30 -0500

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]

Then, your product becomes valid:

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
sage: vC * v
[ 9 12]
[12 16]
edit flag offensive delete link 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.

Gravitus gravatar imageGravitus ( 2014-02-17 06:09:33 -0500 )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

tmonteil gravatar imagetmonteil ( 2014-02-17 07:43:46 -0500 )edit

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

Gravitus gravatar imageGravitus ( 2014-02-17 08:40:08 -0500 )edit

answered 2014-02-17 07:39:36 -0500

How about doing this:

sage: v = vector([3, 4])
sage: vc = v.column()
sage: vr = v.row()
sage: vr * vc
sage: vc * vr
[ 9 12]
[12 16]
edit flag offensive delete link 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?

Gravitus gravatar imageGravitus ( 2014-02-17 08:33:55 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-02-17 05:11:18 -0500

Seen: 282 times

Last updated: Feb 17 '14