简体   繁体   中英

Symbolic Vectors in Equation

Is there a way to include a vector dot product but prevent it from actually performing the dot product. I would just like to eventually simplify an equation that includes dot products but I don't want the dot products themselves to be expanded.

>>> from sympy import MatrixSymbol
>>> x1 = MatrixSymbol('x1', 1,2)
>>> x2 = MatrixSymbol('x2', 1, 2)
looking for something like this
>>> x1.dot(x2)
x1 * x2
so that I can eventually include it in equations
>>> y = (x1.dot(x2) - x2.dot(x1)) * t
>>> y.coeff(t, 1)
>>> x1 * x2 - x2 * x1

A dot product between two row vectors is calculated as a product transpose. At least that gives a 1x1 matrix whose element is the dot product:

In [10]: >>> from sympy import MatrixSymbol
    ...: >>> a = MatrixSymbol('a', 1,2)
    ...: >>> b = MatrixSymbol('b', 1, 2)

In [11]: a * b.T
Out[11]: 
   T
a⋅b 

In [12]: _.as_explicit()
Out[12]: [a₀₀⋅b₀₀ + a₀₁⋅b₀₁]

In [13]: (a * b.T)[0, 0]
Out[13]: a₀₀⋅b₀₀ + a₀₁⋅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