Ask Your Question
1

How to create a symbolic arbitrary dimensional zero vector?

asked 2013-11-06 05:40:35 +0100

gundamlh gravatar image

updated 2013-11-12 12:54:22 +0100

one way:

sage: symbolic_expression(list(zero_vector(k))) 
# k, dim. of vector, k is some fixed integer, e.g. k = 10, 
# many thanks to @tmonteil 

but it is too long!!

edit retag flag offensive close merge delete

Comments

Can you make your wish more explicit ? Is k a fixed number ? Wich order of magnitude ?

tmonteil gravatar imagetmonteil ( 2013-11-06 06:11:46 +0100 )edit

Sorry, it is some fixed integer, e.g. k = 10

gundamlh gravatar imagegundamlh ( 2013-11-06 08:28:14 +0100 )edit

what do you mean by "it is too long" ?

tmonteil gravatar imagetmonteil ( 2013-11-06 09:06:53 +0100 )edit

the length of the string "symbolic_expression(list(zero_vector(k)))", can we use some command like "zero_list(k)"?

gundamlh gravatar imagegundamlh ( 2013-11-06 09:30:27 +0100 )edit

4 Answers

Sort by ยป oldest newest most voted
2

answered 2013-11-06 09:12:59 +0100

tmonteil gravatar image

You can make your expression shorter by typing:

sage: w = zero_vector(SR, 10) ; w
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

You can check that it is the same object:

sage: v = symbolic_expression(list(zero_vector(10)))
sage: v
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
sage: v == w
True
edit flag offensive delete link more

Comments

Thanks! Yes, that is what I want! SR = Symbolic Ring, super.

gundamlh gravatar imagegundamlh ( 2013-11-06 09:32:38 +0100 )edit

Can we create a list whose entries are all 1, using a similar method?

gundamlh gravatar imagegundamlh ( 2013-11-13 10:10:51 +0100 )edit
2

answered 2019-04-19 03:54:29 +0100

nbruin gravatar image

updated 2019-04-19 14:45:31 +0100

slelievre gravatar image

For the follow-up question posted as a comment to @tmonteil's answer:

vector(SR, [1]*10)

is worth mentioning as well. Here, [1]*10 is just the Python way of constructing a list with 10 repeats of 1.

edit flag offensive delete link more
1

answered 2019-04-20 20:33:24 +0100

vdelecroix gravatar image

updated 2019-04-20 20:33:56 +0100

A version with 14 characters

sage: (SR^10).zero()
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

that could even be shorten to 9

sage: (SR^10)()
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
edit flag offensive delete link more
0

answered 2019-04-18 23:06:43 +0100

slelievre gravatar image

This is an answer to the follow-up question posted as a comment to @tmonteil's answer.

There is no function ones_vector but we can define a vector of ones as the first row of a matrix of ones:

sage: v = matrix.ones(SR, 1, 10)[0]
sage: v
(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
sage: v.parent()
Vector space of dimension 10 over Symbolic Ring

It lives in the same space as the zero vector:

sage: u = zero_vector(SR, 10)
sage: u
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
sage: u.parent()
Vector space of dimension 10 over Symbolic Ring
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-11-06 05:40:35 +0100

Seen: 4,809 times

Last updated: Apr 20 '19