while ( true )
clear ; clc;
% clearvars (‘-except’ , keepVars {:} ) % used for loop testing
% generate system param
n=5; nu=4; ny=6; nd=1; nz=1; bny=2^ny ; % generate system parameters
% generate stable A matrix
M1=randn (n) ;
M2=randn (n) ;
M3=randn (n) ;
A=M3*(-M1’M1+(M2-M2’) ) /M3;
% generate marginally stable A matrix
M1_marg=randn (n-1) ; M2_marg=randn (n-1) ; M3_marg=randn (n-1) ;
T=randn (n) ;
A_marg=M3_marg(-M1_marg’M1_marg+(M2_marg-M2_marg’)) /M3_marg ;
A_marg = [ A_marg , zeros(n-1 ,1) ; zeros( 1 , n) ] ;
A_marg = T\A_margT;
% generate unstable A matrix
M1_uns=randn (n-1) ; M2_uns=randn (n-1) ; M3_uns=randn (n-1) ;
T_uns=randn (n) ;
A_uns=M3_uns*(-M1_uns’M1_uns+(M2_uns-M2_uns’) ) /M3_uns ;
A_uns = [ A_uns , zeros(n-1 ,1) ; abs(randn( 1 , n) )] ;
A_uns = T_uns\A_unsT_uns ;
A_mat=[A, A_marg , A_uns ] ;
% generateother system matrices
B=randn (n , nu) ;
C=randn (ny , n) ;
D=zeros ( n , n) ;
Cz=randn ( nz , n) ;
Bd=rand (n , n) ;
Dd=rand (ny , n) ;
%generate faults
Delta=faultsgen ( ny ) ;
% generate eigenvalue place holders
EigenValues=zeros (n , bny ) ;
EigenValuesNFTC=zeros (n , bny ) ; % no fault tolerant control
EigenValuesFTC=zeros (n , bny ) ; % with fault tolerant control
EigenValuesFFTC=zeros (n , bny ) ; % with fast fault tolerant control
%% Non fault tolerant control
cvx_begin sdp
cvx_precision high
variable Y(n , ny ) ;
variable P(n , n) symmetric ;
variable Gamma;
minimize (Gamma) ;
P>=eye (n) ;
BRL=[P*A+A'*P+Y*C+C'*Y',P*Bd+Y*Dd,Cz';
(P*Bd+Y*Dd)',-Gamma*eye(nd) ,D' ;
Cz ,D,-Gamma*eye (nz) ]<=0 ;
cvx_end
L_NFTC=inv(P)*Y;
gamma_NFTC=Gamma;
cvx_NFTC=cvx_optval;
%% Fault tolerant control
cvx_begin sdp
cvx_precision high
variable Y(n , ny ) ;
variable P(n , n) symmetric ;
variable Gamma;
minimize (Gamma) ;
P>=eye (n) ;
for i =1:bny
% lypanouv stability
PA+YDelta ( : , : , i ) C+(PA+Y*Delta ( : , : , i ) *C)'<=0;
end
BRL=[PA+(PA)‘+YC+(YC)’ ,PBd+YDd,Cz’ ;
(PBd+YDd)',-Gammaeye(nd) ,D’ ;
Cz ,D,-Gammaeye(nz) ] ;
BRL<=0;
cvx_end
L_FTC=inv (P)*Y % generate controller gain
gamma_FTC=Gamma
cvx_FTC=cvx_optval
%% Fast fault tolerant control
cvx_begin sdp
cvx_precision high
variable Y(n , ny ) ;
variable P(n , n) symmetric ;
variable S(ny , ny ) diagonal
variable Gamma;
minimize (Gamma) ;
P>=eye (n) ;
% lypanouv stability with relaxation
[PA+(PA)’ , Y+C’S’ ;
Y’+SC,-S-S’]<=0;
BRL=[PA+A’P+YC+C’Y’ ,PBd+YDd,Cz’ ;
(PBd+YDd)',-Gammaeye (nd) ,D’ ;
Cz ,D,-Gamma eye ( nz ) ] ;
BRL<=0;
cvx_end
L_FFTC=inv(P)*Y; % generate controller gain
gamma_FFTC=Gamma;
cvx_FFTC=cvx_optval ;
% check if all cvx has been solved-only move on until solved
cvx_check=[cvx_NFTC cvx_FTC cvx_FFTC ] ;
if ( isempty ( cvx_check ( isinf ( cvx_check ) ) )==1)
break ;
end
end
% testing controllers using simulation model
testScript ;
when i run this code,i show this error:
Error using cvx/cat
All dimensions but the one being concatenated (2) must be equal.
Error in cvx/horzcat (line 2)
y = cat( 2, varargin{:} );
Error in FaultTolerantLS (line 59)
(P*Bd+Y*Dd)',-Gamma*eye(nd) ,D' ;
please ,can you help me for solve this error