如果你確實在help ltitr
在MATLAB命令提示符下鍵入,你想出這個文檔:
%LTITR Linear time-invariant time response kernel.
%
% X = LTITR(A,B,U) calculates the time response of the
% system:
% x[n+1] = Ax[n] + Bu[n]
%
% to input sequence U. The matrix U must have as many columns as
% there are inputs u. Each row of U corresponds to a new time
% point. LTITR returns a matrix X with as many columns as the
% number of states x, and with as many rows as in U.
%
% LTITR(A,B,U,X0) can be used if initial conditions exist.
% Here is what it implements, in high speed:
%
% for i=1:n
% x(:,i) = x0;
% x0 = a * x0 + b * u(i,:).';
% end
% x = x.';
% Copyright 1984-2007 The MathWorks, Inc.
% $Revision: 1.1.6.4 $ $Date: 2007/05/23 18:54:41 $
% built-in function
因此,他們幾乎已經給你它的代碼。不過,我假設這是用MEX編寫的,所以這就是爲什麼它是內置的,並且速度非常快。因此,如果您想將此轉換爲Octave,則只需使用上面提到的代碼即可。雖然它不會像MATLAB的版本一樣快,但是for
循環基本上是實現它的基本方式。
然而,爲了完整起見,我們寫我們自己的八度音功能吧:
function x = ltitr(A, B, U, x0)
%// Number of rows in U is the number of time points
num_points = size(U, 1);
%// Number of columns in U is how many inputs we have
num_inputs = size(U, 2);
x = zeros(num_inputs, num_points); %// Pre-allocate output
%// For each time point we have ...
for idx = 1 : num_points
x(:,idx) = x0; %// Output the corresponding time point
x0 = A*x0 + B*U(idx,:).'; %// Compute next time point
end
x = x.';
上述功能幾乎類似於您在MATLAB看到的代碼,但是有我做了一些額外的步驟例如預先分配矩陣以獲得效率,並獲得一些相關變量以幫助進行計算。另外,請注意,輸出矩陣x
的尺寸爲翻轉。原因是因爲在這個狀態下計算每個時間點的輸出更容易計算。如果您不這樣做,則您必須爲x0 = ...
聲明中定義的其他變量進行不必要的轉置。因此,在轉置矩陣中進行計算更容易。完成後,將轉矩矩陣轉換爲最終輸出矩陣x
。
爲x0
我假設將是全零,所以如果你想用這個作爲默認狀態,指定x0 = zeros(n,1);
其中n
是爲您的LTI系統的總輸入量的默認狀態。