Ask Your Question
0

Why cant I multiply two vectors together on sage cell?

asked 2014-02-17 12:11:18 +0200

Gravitus gravatar image

updated 2014-02-17 12:30:09 +0200

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

2 Answers

Sort by ยป oldest newest most voted
3

answered 2014-02-17 12:44:54 +0200

tmonteil gravatar image

updated 2014-02-17 14:47:30 +0200

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

Comments

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 13:09:33 +0200 )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 14:43:46 +0200 )edit

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

Gravitus gravatar imageGravitus ( 2014-02-17 15:40:08 +0200 )edit
1

answered 2014-02-17 14:39:36 +0200

slelievre gravatar image

How about doing this:

sage: v = vector([3, 4])
sage: vc = v.column()
sage: vr = v.row()
sage: vr * vc
[25]
sage: vc * vr
[ 9 12]
[12 16]
edit flag offensive delete link more

Comments

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 15:33:55 +0200 )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

Stats

Asked: 2014-02-17 12:11:18 +0200

Seen: 1,264 times

Last updated: Feb 17 '14