简体   繁体   中英

How to create vector of symbolic variables in sympy

How to create vector of symbolic variables in sympy? I want to do something like

x, x1, x2, x3 = symbols ('x x1 x2 x3')
A = [x+x1,x+x2,x+x3]
B = A * Transpose(A)
print (B)

A is array of symbolic variables. I checked with sympy documentation , but couldn't figure out.

(Python 2.7.6, sympy 0.7.4.1)

Update:

I want to do something like

x, x1, x2, x3 = symbols ('x x1 x2 x3')
v1e = x+x1
v2e = x+x2
v3e = x+x3
v1 = v1e.subs(x1,1)
v2 = v2e.subs(x2,2)
v3 = v3e.subs(x3,3)
A = Matrix ([v1,v2,v3])
B = A * Transpose(A)
print (B)

But seems that there is problem with v1,.. putting as matrix elements. Any suggestions?

Vectors can be represented as Matrix es in sympy as column-vectors or row-vectors.

from sympy import symbols, Matrix, Transpose
x, x1, x2, x3 = symbols('x x1 x2 x3')
A = Matrix([[x+x1, x+x2, x+x3]])
B = A * Transpose(A)
# or B = A * A.T
print (B)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM