简体   繁体   English

用 ReferenceFrame 向量替换 SymPy sp.Symbol

[英]Replace SymPy sp.Symbol with ReferenceFrame vector

I'm having trouble subbing Symbols for Vectors with the subs function in SymPy.我在 SymPy 中使用subs function 为向量替换符号时遇到问题。 Below is an example of what I'd like to do:下面是我想做的一个例子:

N = ReferenceFrame('N')
zhat, Q, p = sp.symbols('\\hat{\\mathbf{z}} Q p')
expr = 4*Q*zhat/p
old = zhat
new = N.z
expr.subs(old, new)

I believe it necessary, given the context of this problem, to state that I require the initial expression expr to be comprised entirely of Symbols and to have type Mul before the substitution.鉴于此问题的上下文,我认为有必要对 state 要求初始表达式expr完全由Symbols组成,并且在替换之前具有Mul类型。

I haven't found a solution for the exact above problem, but a very similar one:我还没有找到针对上述问题的解决方案,但有一个非常相似的解决方案:

N = CoordSys3D('N')
zhat, Q, p = sp.symbols('\\hat{\\mathbf{z}} Q p')
expr = 4*Q*zhat/p
old = zhat
new = N.k
expr.subs(old, new)

Using CoordSys3D instead of ReferenceFrame allows for substitution.使用CoordSys3D代替ReferenceFrame允许替换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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