2017-01-14 1 views
0

ステップ応答をプロットします。私は状態空間方程式でステップ関数を使うことができることを知っていますが、私はplot関数を使って同じ結果を得ようとします。ここでは、コードの私のサンプルは次のとおりです。ステップ関数を使用しないプロットステップ応答

for i=1:201 
    u(i) = 1; 
    x1(i+1) = (-(b/J)*x1(i) + (K/J)*x2(i)); 
    x2(i+1) = (-(K/L)*x1(i) - (R/L)*x2(i) + (1/L)*u(i)); 
    y(i) = x1(i); 
end 

、これは状態空間方程式である:

A = [-b/J K/J 
    -K/L -R/L]; 
B = [0 
    1/L]; 
C = [1 0]; 
D = 0; 

私が行う場合:

t = 0:1:200; 
plot(t, y) 

それが動作していないと私は持っていたいです以下のステップ関数のような同じ結果:

sys = ss(A,B,C,D); 
step(sys) 

あなたは私の状態空間方程式hereを見つけることができます。

答えて

1

不一致の理由は、sysは連続時間モデルですが、yの計算では離散時間システムとして扱われます。

次は離散時間領域で連続時間系のステップ応答を推定する方法である:

% Given from the problem statement 
A = [-b/J K/J 
    -K/L -R/L]; 
B = [0 
    1/L]; 
C = [1 0]; 
D = 0; 

% this is your continuous-time model 
sys = ss(A,B,C,D); 

% define the sample rate of the equivalent discrete-time model 
Ts = 1/10; 
% this needs to be something smaller than the time-constants in your model, 
% so that you have enough resolution to represent the continuous-time 
% signal. 

% convert the system to the equivalent discrete-time model 
sysd = c2d(sys,Ts); 

% define how long a step response you'd like to compute 
T = 7; 
% this should be long enough to cover the length of the step response 


t = 0:Ts:T; % time-grid for the plot 
nSmp = length(t); % total number of samples to be computed 

% initializations 
y = NaN(1, nSmp); % output vector 
u = ones(1, nSmp); % unit step input 
X = [0; 0]; % state vector, initialized to 0 

% compute the samples of the step-response 
% (i prefer to use vectorized form to keep the code concise) 
for i=1:nSmp 
    y(i) = sysd.C * X + sysd.D * u(i); 
    X = sysd.A * X + sysd.B * u(i); 
end 

% plot continous-time step response 
figure; 
step(sys); 

% plot simulated discrete-time step response 
figure; 
plot(t, y, 'r') 
xlabel('Time (s)'); 
ylabel('Amplitude'); 
title('Simulated Step Response'); 
+0

は偉大である、どうもありがとうございました。次に、私はPIDコントローラを追加する必要があります。あなたは、エラー、intagretionエラーと派生エラーを取得する方法を教えていただけますか?遺伝的アルゴリズムによってPIDパラメータを生成するには、この3つの値が必要です。 – Masaj

+0

@Masaj:私はそれに適切に答えることができないのではないかと恐れています。新しい質問としてそれを掲示するほうが、他人ができるようになる方が良いでしょう。 – aksadv

+0

私は既に新しいものを尋ねます。再びありがとう – Masaj

関連する問題