필터 지우기
필터 지우기

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 CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by