简体   繁体   English

Sympy:如何计算矩阵相对于矢量场的李导数

[英]Sympy: How to compute Lie derivative of matrix with respect to a vector field

I have a system(x'=f(x)+g(x)u), such that f(x) is f:R3->R3 and g(x) is g:R3->R(3x2) . 我有一个系统(x'= f(x)+ g(x)u),这样f(x) is f:R3->R3g(x) is g:R3->R(3x2) My system is 我的系统是

在此输入图像描述 在此输入图像描述

As you can see, it is a MIMO nonlinear control system and I wish to find the controllability matrix for my system. 如您所见,它是一个MIMO非线性控制系统,我希望找到我的系统的可控性矩阵。 Controllability matrix in this case is formulated by 在这种情况下,可控性矩阵由下式表示
C=[g [f,g] [f,[f,g]] ..], C = [g [f,g] [f,[f,g]] ..],
where [f,g] denotes the lie bracket operation between f and g. 其中[f,g]表示f和g之间的斜括号操作。 That is the reason why I need to compute Lie derivative of a matrix with respect to a vector field and vice versa. 这就是我需要相对于矢量场计算矩阵的李导数的原因,反之亦然。 Because [f,g]=f dg/dx-g df/dx 因为[f,g] = f dg / dx-g df / dx

Here in my system, f is 3x1 and g is 3x2 as there are two inputs available. 在我的系统中,f是3x1,g是3x2,因为有两个输入可用。 And I wish to calculate the above matrix C in Python. 我希望用Python计算上面的矩阵C. My system is 我的系统是
f=sm.Matrix([[x1**2],[sin(x1)+x3**2],[cos(x3)+x1**2]]) and f=sm.Matrix([[x1**2],[sin(x1)+x3**2],[cos(x3)+x1**2]])
g=sm.Matrix([[cos(x1),0],[x1**2,x2],[0,0]]) . g=sm.Matrix([[cos(x1),0],[x1**2,x2],[0,0]])

My code is: 我的代码是:

from sympy.diffgeom import *
from sympy import sqrt,sin,cos

M     = Manifold("M",3)
P     = Patch("P",M)

coord          = CoordSystem("coord",P,["x1","x2","x3"])
x1,x2,x3       = coord.coord_functions()
e_x1,e_x2,e_x3 = coord.base_vectors()

f      = x1**2*e_x1 + (sin(x1)+x3**2)*e_x2 + (cos(x3) + x1**2)*e_x3
g      = (cos(x1))*e_x1+(x1**2,x2)*e_x2 + 0*e_x3

#h1    = x1
#h2    = x2
#Lfh1  = LieDerivative(f,h1)
#Lfh2  = LieDerivative(f,h2)
#print(Lfh1)
#print(Lfh2)

Lfg    = LieDerivative(f,g)
print(Lfg)

Why isn't my code giving me correct answer? 为什么我的代码没有给我正确答案?

The only error in your code is due to the tuple used for multiple inputs. 代码中唯一的错误是由于用于多个输入的元组。 For LieDerivative in Sympy.diffgeom to work you need a vector field defined properly. 对于Sympy.diffgeom中的LieDerivative,你需要一个正确定义的矢量场。

For single input systems, the exact code that you have works without the tuple, so, in that case, for example if you have g = (cos(x1))*e_x1+x1**2*e_x2 + 0*e_x3 对于单输入系统,你所使用的确切代码没有元组,因此,在这种情况下,例如,如果你有g = (cos(x1))*e_x1+x1**2*e_x2 + 0*e_x3

(that is g(x) is 3 x 1 matrix with just the first column). (即g(x)是3 x 1矩阵,只有第一列)。 Then, making the above change, you get the correct Lie derivatives. 然后,进行上述更改,即可获得正确的Lie导数。

For multiple input case, (as in your question), you can simply separate the two columns into g1 and g2 and proceed as the above case. 对于多输入情况(如您的问题),您可以简单地将两列分成g1和g2,并按上述情况进行操作。 This works because for multiple inputs case, See math here 这有效,因为对于多输入情况, 请参见此处的数学

where g_1 and g_2 are the two columns. 其中g_1和g_2是两列。 The final result for Lgh is a 1 x 2 matrix which you can basically get if you have the two results calculated above (Lg1h and Lg2h). Lgh的最终结果是1 x 2矩阵,如果你有上面计算的两个结果(Lg1h和Lg2h),你基本上可以得到。

Code - 代码 -

from sympy.diffgeom import *
from sympy import sqrt,sin,cos
from sympy import *
M = Manifold("M",3)
P = Patch("P",M)

coord          = CoordSystem("coord",P,["x1","x2","x3"])
x1,x2,x3       = coord.coord_functions()
e_x1,e_x2,e_x3 = coord.base_vectors()

f  = x1**2*e_x1 + (sin(x1)+x3**2)*e_x2 + (cos(x3) + x1**2)*e_x3
g1 = (cos(x1))*e_x1+(x1**2)*e_x2 + 0*e_x3
g2 = 0*e_x1+ x2*e_x2 + 0*e_x3
h = x1

Lg1h = LieDerivative(g1,h)
Lg2h = LieDerivative(g2,h)
Lgh = [Lg1h, Lg2h]
print(Lgh)

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

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