Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create vector of symbolic variables in sympy

Tags:

python

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?

like image 556
user7423098 Avatar asked Jan 29 '17 23:01

user7423098


1 Answers

Vectors can be represented as Matrixes 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)
like image 98
Ilya V. Schurov Avatar answered Sep 27 '22 17:09

Ilya V. Schurov