フィルターのクリア

State Matrix and Output of LTI System

3 ビュー (過去 30 日間)
ali veysel
ali veysel 2012 年 3 月 20 日
Hello Dear All, My matrix is as of the following:
%xdot=A*x+B*u
%y=C*x+D*u
A=[0 1 0 ; 0 0 1; -2 -4 -3];
B=[1 0;0 1; -1 1];
C=[0 1 -1; 1 2 1];
D=[0 0;0 0];
x=[1;0;0]; %initial condition
I want to evaluate x and y for t=0:1:10 and u=[1;1] as of below but i could not succeed.
T=1
maxt=10
for t=1:maxt/T
u(t)=[1;1];
x(:,t+1)=(eye(n)+T*A)*x(:,t)+T*B*u(t);
end
Would you be kind to help me?
Ps. I was asked to determine the state x(t) from 0 to 10 and the output y(t) of the LTI system

回答 (4 件)

Rick Rosson
Rick Rosson 2012 年 3 月 20 日
Please format your code.
  2 件のコメント
ali veysel
ali veysel 2012 年 3 月 20 日
sorry, done.
Rick Rosson
Rick Rosson 2012 年 3 月 20 日
Thanks!

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


Rick Rosson
Rick Rosson 2012 年 3 月 20 日
Do you have access to the Control System Toolbox, or just core MATLAB itself?

Rick Rosson
Rick Rosson 2012 年 3 月 20 日
Please try:
%%Time specifications
stopTime = 10;
Fs = 1;
dt = 1/Fs;
t = (0:dt:stopTime)';
N = size(t,1);
%%State space model
A=[0 1 0 ; 0 0 1; -2 -4 -3];
B=[1 0;0 1; -1 1];
C=[0 1 -1; 1 2 1];
D=[0 0;0 0];
%%Pre-allocation
u = zeros(2,N);
x = zeros(3,N);
y = zeros(2,N);
%%Initial conditions
u(:,1) = [ 1 ; 1 ];
x(:,1) = [ 1 ; 0 ; 0 ];
y(:,1) = ...
%%Simulation - main loop
for k = 2:N
u(:,k) = [ 1 ; 1 ];
x(:,k) = x(:,k-1) + dt*( ... );
y(:,k) = ...
end
%%Plot results
figure;
ax(1) = subplot(2,1,1);
plot(t,x);
ax(2) = subplot(2,1,2);
plot(t,y);
linkaxes(ax,'x');
HTH.
Rick
  1 件のコメント
ali veysel
ali veysel 2012 年 3 月 21 日
Rick,
Thank you a lot for your help on this!
The formulas are like this as you konw already:
xdot=Ax+Bu
y=Cx+Du
For the simulation main loop, i believe i got it wrong:
u(:,k) = [ 1 ; 1 ];
x(:,k) = x(:,k-1) + dt*u(:,k);
y(:,k) = y(:,k)*x(:,k)

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


Rick Rosson
Rick Rosson 2012 年 3 月 21 日
Close, but not quite correct. In the main loop, you need to use the state space model to compute the updated state variables x and the value of the output variables y. So x(:,k) should depend on A and B. Likewise, y(:,k) should depend on C and D.
Take the equations as given, and then write them out in the form of MATLAB code using the appropriate variables. Double check to make sure that the inner dimensions match on each matrix multiplication.
Hint:
xdot = dx/dt
dx = x_k - x_k-1
Therefore
x_k = . . . ?
  2 件のコメント
ali veysel
ali veysel 2012 年 3 月 21 日
I got your point I guess:
u(:,k)=[1;1];
x(:,k+1)=(eye(n1)+T*A)*x(:,k)+(T*B*u(:,k));
y(:,k)=(C)*x(:,k);
changed my code like this now i think i got the correct results.
Rick Rosson
Rick Rosson 2012 年 3 月 21 日
It looks much better now. You may need to change the subscripting on the 2nd line to avoid an out of bounds error. Try x(:,k) = ... x(:,k-1) ... u(:k-1)

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by