Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

Why cant I multiply two vectors together on sage cell?

asked 11 years ago

Gravitus gravatar image

updated 11 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
3

answered 11 years ago

tmonteil gravatar image

updated 11 years ago

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×1 by another 2×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]
Preview: (hide)
link

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 ( 11 years ago )

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 ( 11 years ago )

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

Gravitus gravatar imageGravitus ( 11 years ago )
1

answered 11 years ago

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]
Preview: (hide)
link

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 ( 11 years ago )

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: 11 years ago

Seen: 1,669 times

Last updated: Feb 17 '14