Ask Your Question

# Concatenation of symbolic vectors.

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

## 2 Answers

Sort by » oldest newest most voted

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]

more

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)

more

## Comments

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

( 2020-08-04 07:34:52 +0200 )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)

( 2020-08-04 08:56:50 +0200 )edit

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

( 2020-08-04 12:18:33 +0200 )edit

## Your Answer

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

Add Answer

## Stats

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

Seen: 569 times

Last updated: Aug 04 '20