0
我想驗證我的RK4代碼並且有一個狀態空間模型來解決同一個系統。我有一個具有初始條件的14狀態系統,但條件隨時間變化(每次迭代)。我試圖制定A,B,C,D矩陣,並使用sys
和lsim
以便在整個時間範圍內編譯我所有狀態的結果。我試圖做類似這樣的:用變量矩陣求解狀態空間響應
for t=1:1:5401
y1b=whatever
.
.
y14b = whatever
y_0 = vector of ICs
A = (will change with time)
B = (1,14) with mostly zeros and 3 ones
C = ones(14,1)
D = 0
Q = eye(14)
R = eye(1)
k = lqr(A,B,C,D)
A_bar = A - B*k
sys = ss(A_bar,B,C,D)
u = zeros(14,1)
sto(t,14) = lsim(sys,u,t,y_0)
then solve for new y1b-y14b from outside function
end
換句話說,我想使用sto(t,14)
每次迭代存儲lsim
,並與所有我的狀態爲從1到每個時間段的矩陣結束5401我不斷收到此錯誤信息:
Error using DynamicSystem/lsim (line 85)
In time response commands, the time vector must be real, finite, and must contain
monotonically increasing and evenly spaced time samples.
和
Error using DynamicSystem/lsim (line 85)
When simulating the response to a specific input signal, the input data U must be a
matrix with as many rows as samples in the time vector T, and as many columns as
input channels.
任何有用的輸入是極大的讚賞。謝謝
謝謝你的幫助。我試着按照你所說的去做,但它告訴我最初的條件必須與14的狀態相同。我試着用14步將s從t-1拉伸到t,並且使它的大小爲14告訴我有一個下標不匹配。有任何想法嗎? – user3814258
'y_0'的大小是多少?這聽起來像是'14×1',在這種情況下,我不明白你想要做什麼。 – Simon
這是y_0的正確大小,因爲它是14個狀態的初始條件。我試圖求解x_dot = Ax + Bu和y = Cx + Du,其中狀態嵌入A矩陣的公式中,但也隨時間變化。這意味着我必須爲每個時間步驟循環lsim並且每次都解析A矩陣。最後,我想要一個從1-5401開始的每個時間的所有狀態值的矩陣,我只關心整個數字時間 – user3814258