Ask Your Question

append a variable to a vector

asked 2013-08-15 06:23:40 +0100

Tomas gravatar image

updated 2013-08-15 06:58:23 +0100

I would like to define a new vector in Sage $\vec{u} = [O, P, \sigma]$ using a previously defined vecotor $\vec{x} = [O, P]$ and a new variable $\sigma$.

My code looks like:

var(’O, P');


x = vector([O,P]);

u = vector([x, sigma]);

Which gives an error:

TypeError: unable to find a common ring for all elements

Apparently this is because vector() requires the variables to be of the same ring. In my case


Vector space of dimension 2 over Symbolic Ring


sigma.parent() Symbolic Ring

There is any way how to connect this two objects ($\vec{x}$, $\sigma$) together to create one vector?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2013-08-15 08:36:41 +0100

Tomas gravatar image

updated 2013-08-15 08:40:29 +0100

So an solution which work is to convert the vector to a list, append the new variable and convert to a vector again. The code for that would be as follows:

u = x.list()


u = vector(u)

Do you see any potential problems with this solution? Why there is no method append in vector? Could I do better?

edit flag offensive delete link more



The short answer to your question about vector is that a vector in Sage is not the same as a "vector" in other languages. Python lists correspond to that notion. A vector in Sage is a *mathematical* object, and there is no one way to make a (say) 3-d vector a 4-d vector. One could indeed add a dimension, but where? It would be (mathematically) just as natural to do it 'in front' as 'in back'. Your solution is actually a good one, and has the advantage that if your original vectors live in two different spaces (say, over QQ and RR) then your new vector will still make sense.

kcrisman gravatar imagekcrisman ( 2013-08-15 10:09:59 +0100 )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


Asked: 2013-08-15 06:23:40 +0100

Seen: 3,169 times

Last updated: Aug 15 '13