sympy 中的抽象矩阵代数和微积分
我正在做控制工程,经常遇到以下类型的问题,我想知道是否有办法在 sympy 中处理这个问题。
问题: tl:dr:我想创建一个依赖于表示时间的标量 Symbol
的 MatrixSymbol,以允许对时间进行微分。
实际问题:v(t)=[v1(t),v2(t),v3(t)]
是时间t
的向量函数,我想计算 v 方向的投影及其时间导数。最后,我希望得到 v
、v.diff(t)
和 vT
(转置)的表达式。
尝试:
我尝试了不同的方法并展示了最接近的一个:
这确实是我需要的代数,但我不能对时间进行导数
v = MatrixSymbol('v',3,1)
# here i'm building the terms I want
projection_v = v*sqrt(v.T*v).inverse()*v.T
orthogonal_v = Identity(3)-projection_v
orthogonal_v.as_explicit()
orthogonal_v
显示了我的抽象方程形式需要。最后 - 为了再次检查和查看结果,我还想将其明确化并将表达式视为 v[0,0]
, v[1, 0]
和 MatrixSymbol 的 v[2,0]
函数 .as_explicit()
从 sympy 版本 1.10 开始完全执行此操作。 (感谢 Francesco Bonazzi 指出了这一点。)
然而问题是,我无法将它们作为 t
的函数并取 projection_v
相对于时间 的导数t 。
我也尝试过
t = Symbol('t',real=True,positive=True)
v1 = Function('v1',real=True)(t)
v2 = Function('v2',real=True)(t)
v3 = Function('v3',real=True)(t)
v_mat = FunctionMatrix(3,1,[v1,v2,v3]);
,但似乎 FunctionMatrix
是为了直接评估函数,而不是模拟标量 Function
。
实际上,我希望能够计算orthogonal_v.diff(t)
,然后使用orthogonal_v.diff(t).as_explicit()
之类的东西查看组件明智的操作。这可能吗?
I am doing control engineering and I often face problems of the type below and I want to know if there is a way to deal with this in sympy.
question:
tl:dr: I want to make a MatrixSymbol
dependent on a scalar Symbol
representing time, to allow differentiation w.r.t. time.
Actual problem: v(t)=[v1(t),v2(t),v3(t)]
is a vector function of the time t
and I want to calculate the Projection into the direction of v and it's time derivative. In the end I would love to get an expression of v
, v.diff(t)
and v.T
(the transpose).
attempts:
I've tried different things and show the closest one:
This does the algebra I need, but I cannot take derivatives w.r.t. time
v = MatrixSymbol('v',3,1)
# here i'm building the terms I want
projection_v = v*sqrt(v.T*v).inverse()*v.T
orthogonal_v = Identity(3)-projection_v
orthogonal_v.as_explicit()
orthogonal_v
shows the abstract equation form that I need. In the end - to check and see the result again, I'd also like to make it explicit and see the expression as a function of v[0,0]
, v[1,0]
, and v[2,0]
for MatrixSymbol the function .as_explicit()
does exactly that beginning with sympy version 1.10. (Thanks Francesco Bonazzi for pointing this out.)
The problem however is, that I cannot make these a function of t
and take the derivative of projection_v
w.r.t. the time t
.
I also tried
t = Symbol('t',real=True,positive=True)
v1 = Function('v1',real=True)(t)
v2 = Function('v2',real=True)(t)
v3 = Function('v3',real=True)(t)
v_mat = FunctionMatrix(3,1,[v1,v2,v3]);
but it seems FunctionMatrix
is meant to evaluate the functions directly instead of being an analog to the scalar Function
.
Effectively I want to be able to calculate orthogonal_v.diff(t)
and then see the component wise operations with something like orthogonal_v.diff(t).as_explicit()
. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论