Differences in simulation results in state space models using matlab

4 ビュー (過去 30 日間)
Andrew Wileman
Andrew Wileman 2013 年 12 月 12 日
コメント済み: Andrew Wileman 2013 年 12 月 12 日
Hi,
I'm writing some code to simulate a relay dynamically. I've derived differential equations, linearised them around an operating point and put into state space form. Firstly, I checked the impulse and step response at the operating input using the state space function in matlab, the response was ok. I then implemented the same equations in code (see attached) and the impulse response is different, in fact unstable - any ideas anyone?
Cheers,
Andy

採用された回答

Suneesh
Suneesh 2013 年 12 月 12 日
You are using continuous SS coefficients while you are (discrete) simulating your system in:
% Perform the system simulation:
x = x0; % Set initial state
for n=1:Ns-1 % Iterate through time
y(n) = C*x + D*u(n); % Output for time n-1
x = A*x + B*u(n); % State transitions to time n
end
y' % print the output y (transposed)
%plot(y')
Instead use the discrete coefficients, which you already have available in 'sysd':
discA = sysd.a;
discB = sysd.b;
discC = sysd.c;
discD = sysd.d;
Then try:
x = x0; % Set initial state
for n=1:Ns-1 % Iterate through time
y(n) = discC*x + discD*u(n); % Output for time n-1
x = discA*x + discB*u(n); % State transitions to time n
end
y' % print the output y (transposed)
%plot(y')
  1 件のコメント
Andrew Wileman
Andrew Wileman 2013 年 12 月 12 日
Hi,
Thanks Suneesh for your help, works fine now.
Once again many thanks,
Andy

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by