Ask Your Question
0

Concatenation of symbolic vectors.

asked 2020-08-03 19:53:17 +0100

Cyrille gravatar image

This

NB_0=vector(var('x', n=3, latex_name='x'))
B_0=vector(var('y', n=4, latex_name='ϵ'))
show(LatexExpr(r"NB_0 =" + latex(NB_0)),LatexExpr(r"\, \text{ et }\, B_0 =" + latex(B_0)))

gives me two vectors.

But I need to concatenate them -- i.e. to create a vector $V1= [x_1, x_2, x_3, x_4, \epsilon_1, \epsilon_2, \epsilon_3, b]$ (I need the $b$) and $V2= [\epsilon_1, \epsilon_2, \epsilon_3, z]$ (I need the $z$). And when I call them in a table I want to create I need the Latex names not the sagemath one. How could I do ?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2020-08-04 10:14:55 +0100

dan_fulea gravatar image

It is hard to understand what and why should be done, but maybe the following will do the job. The presented solution is just blind plain work to avoid follow up questions. (It is hard to understand why vectors should be used, lists are better suited. And lists can be easily concatenated. But ok... )

x1 = var('x1', latex_name='x_1')                                                                                                                        
x2 = var('x2', latex_name='x_2')                                                                                                                        
x3 = var('x3', latex_name='x_3')                                                                                                                        
x4 = var('x4', latex_name='x_4')                                                                                                                        

e1 = var('e1', latex_name=r'\epsilon_1')                                                                                                                
e2 = var('e2', latex_name=r'\epsilon_2')                                                                                                                
e3 = var('e3', latex_name=r'\epsilon_3')                                                                                                                

b  = var('b' , latex_name='b')                                                                                                                          

v = [x1, x2, x3, x4, e1, e2, e3, b]

Then in the sage interpreter:

sage: vector(v)                                                                                                                                               
(x1, x2, x3, x4, e1, e2, e3, b)
sage: show(vector(v))                                                                                                                                         
\newcommand{\Bold}[1]{\mathbf{#1}}\left({x_1},\,{x_2},\,{x_3},\,{x_4},\,{\epsilon_1},\,{\epsilon_2},\,{\epsilon_3},\,{b}\right)
sage: latex(v)                                                                                                                                                
\left[{x_1}, {x_2}, {x_3}, {x_4}, {\epsilon_1}, {\epsilon_2}, {\epsilon_3}, {b}\right]
edit flag offensive delete link more
0

answered 2020-08-04 01:13:29 +0100

slelievre gravatar image

Not sure I understand the question. Maybe this helps a little.

Names are slightly changed with respect to the question.

Define two vectors and two symbolic variables:

sage: A = vector(var('x', n=3, latex_name='x'))
sage: B = vector(var('y', n=4, latex_name=r'\epsilon'))
sage: b = SR.var('b', latex_name='b')
sage: z = SR.var('z', latex_name='z')

Produce two new vectors combining the above:

sage: U = vector(SR, len(A) + len(B) + 1, A.list() + B.list() + [b])
sage: U
(x0, x1, x2, y0, y1, y2, y3, b)

sage: V = vector(SR, len(B) + 1, B.list() + [z])
sage: V
(y0, y1, y2, y3, z)
edit flag offensive delete link more

Comments

It' was nearly what I was expecting less we lost the $\epsilon$

Cyrille gravatar imageCyrille ( 2020-08-04 07:34:52 +0100 )edit

we can see $\epsilon$ with show()

A = vector(var('x', n=3, latex_name='x'))
B = vector(var('y', n=4, latex_name=r'\epsilon'))
b = SR.var('b', latex_name='b')
z = SR.var('z', latex_name='z')
U = vector(SR, len(A) + len(B) + 1, A.list() + B.list() + [b])
V = vector(SR, len(B) + 1, B.list() + [z])
show('U : ',U)
show('V : ',V)
ortollj gravatar imageortollj ( 2020-08-04 08:56:50 +0100 )edit

Thanks for your kind answer but I have a problem I will explain it in another question. It will be easier.

Cyrille gravatar imageCyrille ( 2020-08-04 12:18:33 +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

1 follower

Stats

Asked: 2020-08-03 19:53:17 +0100

Seen: 652 times

Last updated: Aug 04 '20