[英]Sympy: How to compute Lie derivative of matrix with respect to a vector field
我有一個系統(x'= f(x)+ g(x)u),這樣f(x) is f:R3->R3
和g(x) is g:R3->R(3x2)
。 我的系統是
如您所見,它是一個MIMO非線性控制系統,我希望找到我的系統的可控性矩陣。 在這種情況下,可控性矩陣由下式表示
C = [g [f,g] [f,[f,g]] ..],
其中[f,g]表示f和g之間的斜括號操作。 這就是我需要相對於矢量場計算矩陣的李導數的原因,反之亦然。 因為[f,g] = f dg / dx-g df / dx
在我的系統中,f是3x1,g是3x2,因為有兩個輸入可用。 我希望用Python計算上面的矩陣C. 我的系統是
f=sm.Matrix([[x1**2],[sin(x1)+x3**2],[cos(x3)+x1**2]])
和
g=sm.Matrix([[cos(x1),0],[x1**2,x2],[0,0]])
。
我的代碼是:
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)
為什么我的代碼沒有給我正確答案?
代碼中唯一的錯誤是由於用於多個輸入的元組。 對於Sympy.diffgeom中的LieDerivative,你需要一個正確定義的矢量場。
對於單輸入系統,你所使用的確切代碼沒有元組,因此,在這種情況下,例如,如果你有g = (cos(x1))*e_x1+x1**2*e_x2 + 0*e_x3
(即g(x)是3 x 1矩陣,只有第一列)。 然后,進行上述更改,即可獲得正確的Lie導數。
對於多輸入情況(如您的問題),您可以簡單地將兩列分成g1和g2,並按上述情況進行操作。 這有效,因為對於多輸入情況, 請參見此處的數學
其中g_1和g_2是兩列。 Lgh的最終結果是1 x 2矩陣,如果你有上面計算的兩個結果(Lg1h和Lg2h),你基本上可以得到。
代碼 -
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.