MATLAB Answers

0

The length of the initial condition X0 must match the number of states.

Asked by boutros baqain on 4 Aug 2019
Latest activity Commented on by boutros baqain on 4 Aug 2019
hello everyone i cant seem to figure out what the problem with my code. it keeps giving me an error regarding the initial state. any help would be appreciated.
thanks!
here is my code.
A= [0 1 0; 0 0 1; -52 -30 -4];
B = [0;0;1];
C = [20 1 0];
D = [0];
% compute open loop state space
sys_OL = ss(A,B,C,D);
% scaling the B matrix
w = -C/A*B;
% open loop state space with scaled input
sys_OL2 = ss(A, B/w, C, D);
p0 = 5;
Ts = 2;
term = pi^2 +log(p0/100)^2;
zeta = abs(log(p0/100))/sqrt(term);
wn = 4 /Ts/zeta;
beta = sqrt(1-zeta^2);
p3 = 10 * zeta *wn
eigDes = [-zeta*wn+j*wn*beta -zeta*wn-j*wn*beta -p3 -20+i]
% compute the close loop
Ae= [0 1 0 0; 0 0 1 0; -52 -30 -4 0; -20 -1 0 0];
Be = [0;0;1; 0];
Ce = [20 1 0 0];
De = [0];
Br = [0;0;0;1]
Ke = acker(Ae, Be,eigDes) % gain matrix
sys_Cl = ss(Ae - Be*Ke, Br ,Ce,De) %transfer function of close loop
t = 0:0.001:5;
u = ones(size(t));
x0 = [0.01; 0; 0; 0];
x0hat = [0; 0; 0; 0 ];
yOL = lsim(sys_OL2, u, t, x0);
yCl = lsim(sys_Cl, u, t, [x0; x0hat]);

  1 Comment

Sign in to comment.

Tags

0 Answers