State Matrix and Output of LTI System
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (4개)
Rick Rosson
2012년 3월 20일
Do you have access to the Control System Toolbox, or just core MATLAB itself?
댓글 수: 0
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
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
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 Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!