State Matrix and Output of LTI System
3 views (last 30 days)
Show older comments
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 Comments
Answers (4)
Rick Rosson
on 20 Mar 2012
Do you have access to the Control System Toolbox, or just core MATLAB itself?
0 Comments
Rick Rosson
on 20 Mar 2012
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
on 21 Mar 2012
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 Comments
Rick Rosson
on 21 Mar 2012
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)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!