Reputation: 147
Looking in the Documentantion of the vector package I did not find any way to take the cross/dot product of two vectors without evaluating the expression, e.g. without simplify the recurring terms in the result of the operation. Is this possible?
Upvotes: 2
Views: 2136
Reputation: 1957
Supposing you have the latest development version:
In the vector module there are the dot
and cross
functions that calculate the dot and cross products, and the classes Dot
and Cross
that create an unevaluated expression representing the same products.
Import the vector module and SymPy:
In [1]: from sympy import *; from sympy.vector import *
Define a coordinate system:
In [2]: C = CoordSys3D("C")
At this point, C.i, C.j, C.k
are the base vectors.
Cross product with immediate evaluation (lowercase cross
):
In [3]: cross(C.i, C.j)
Out[3]: C.k
Let's use a nice printer to print the cross product as an operator:
In [4]: init_printing()
Cross product in unevaluated form (name with capital C letter Cross
):
In [5]: Cross(C.i, C.j)
Out[5]: (C_i)×(C_j)
To perform the calculation, just use .doit()
:
In [6]: Cross(C.i, C.j).doit()
Out[6]: C_k
Upvotes: 2