📄 sdmdemo.m
字号:
' - n = size(x ) , q1 = size(w1) , q2 = size(w2) , m = size(u)\n',... ' - p1 = size(z1)\n',... ' - p2 = size(z2)\n\n',... 'For the demo a random example is generated\n',... 'choose the size in thne ui menu\n\n']); fprintf('%s\n',write); headerr='Choose the size of the system'; itemm1='n=3 ; q1=2 ; q2=1 ; m=1 ; p1=1 ; p2=2; (small size)'; itemm2='n=10 ; q1=2 ; q2=2 ; m=3 ; p1=2 ; p2=4; (medium size)'; itemm3='n=30 ; q1=4 ; q2=3 ; m=4 ; p1=2 ; p2=4; (large size)'; itemm = menu(headerr,itemm1,itemm2,itemm3); switch itemm case 1 n=3 ; q1=2 ; q2=1 ; m=1 ; p1=1 ; p2=2; case 2 n=10 ; q1=2 ; q2=2 ; m=3 ; p1=2 ; p2=4; case 3 n=30 ; q1=4 ; q2=3 ; m=4 ; p1=2 ; p2=4; end; A =sprand(n,n,1)-speye(n); B1=sprand(n,q1,1); B2=sprand(n,q2,1); B =sprand(n,m ,1); C1=sprand(p1,n,1); D1=sprand(p1,q1,1); E1=sprand(p1,m,1); C2=sprand(p2,n,1); E2=sprand(p2,m,1); eval(next2); write = sprintf(['Solve the H2/Hinfty state-feedback synthesis problem\n',... 'such that u=K.x guarantees for the closed loop:\n\n',... ' (1) Hinfty norm of the transfer w1 -> z1 minimized and less than G1=10\n',... ' (2) H2 norm of the transfer w2 -> z2 minimized \n\n']); G1=10; eval(next1);eval(next2); write = sprintf(['An LMI-based formulation of this problem writes for example as:\n\n',... ' - variables :',... '\n\t X ( n x n ) symmetric',... '\n\t T ( p2 x p2 ) symmetric',... '\n\t S ( m x n )',... '\n\t g scalar\n\n',... ' - constraints :\n\n',... '\t 0 < X\n\n',... '\t [ A*X+X*A''+B*S+B''*S''+B1*B1 , X*C1''+S''*E1''+B1*D1'' ]\n',... '\t [ C1*X+E1*S+D1*B1'' , -g*I+D1*D1'' ] < 0\n\n',... '\t A*X+X*A''+B*S+S''*B''+B2*B2'' < 0\n\n',... '\t [ -T , C2*X+E2*S ]\n',... '\t [ X*C2''+S''*E2'' , -X ] < 0\n\n',... '\t gamma < G1^2\n\n',... ' - objective :\n\n',... '\t G2^2 = min trace(T) + g \n\n']); eval(next1);eval(next2); write = sprintf(['For SeDuMi Interface the constraints are for example rewritten as:\n\n',... '\t 0 < X\n\n',... '\t He{ [ A*X+ B*S , 0 ] } + [ B1 ]*[ B1 ]'' < [ 0 , 0 ]\n',... '\t { [ C1*X+E1*S , 0 ] } [ D1 ] [ D1 ] [ 0 , g*I ] \n\n',... '\t He{ A*X+B*S } + B2*B2'' < 0\n\n',... '\t He{ [ 0 , C2*X+E2*S ] } < [ T , 0 ]\n',... '\t { [ 0 , 0 ] } [ 0 , X ]\n\n',... '\t g < G1^2 \n\n']); eval(next1);eval(next2); write1 = sprintf(['The optimization problem is declared with SeDuMi Interface as follows\n\n',... 'INITIALIZE PROBLEM \n\n',... ' >> quiz = sdmpb(''H2/Hinfty state-feedback synthesis'');\n\n']); write2 = sprintf(['DECLARE VARIABLES\n\n',... ' >> [quiz,Xindex] = sdmvar(quiz, n, ''s'', ''X'');\n',... ' >> [quiz,Tindex] = sdmvar(quiz, p2, ''s'', ''T'');\n',... ' >> [quiz,Sindex] = sdmvar(quiz, m, n, ''S'');\n',... ' >> [quiz,gindex] = sdmvar(quiz, 1, 1, ''g'');\n\n']); write3 = sprintf(['DECLARE CONSTRAINTS\n\n',... ' >> [quiz,c1] = sdmlmi(quiz, n, ''X>0'');\n',... ' >> quiz = sdmineq(quiz, -c1 , Xindex);\n',... ' >> [quiz,c2] = sdmlmi(quiz, [n p1], ''Hinf'');\n',... ' >> quiz = sdmineq(quiz, [c2 1 1], Xindex, A, 1);\n',... ' >> quiz = sdmineq(quiz, [c2 1 1], Sindex, B, 1);\n',... ' >> quiz = sdmineq(quiz, [c2 2 1], Xindex, C1, 1);\n',... ' >> quiz = sdmineq(quiz, [c2 2 1], Sindex, E1, 1);\n',... ' >> quiz = sdmineq(quiz, c2 , 0 , [B1;D1]);\n',... ' >> quiz = sdmineq(quiz,[-c2 2 2], gindex);\n',... ' >> [quiz,c3] = sdmlmi(quiz,n,''gram'');\n',... ' >> quiz = sdmineq(quiz, c3 , Xindex, A, 1);\n',... ' >> quiz = sdmineq(quiz, c3 , Sindex, B, 1);\n',... ' >> quiz = sdmineq(quiz, c3 , 0 , B2);\n']); write4 = sprintf([' >> [quiz,c4] = sdmlmi(quiz, [p2 n],''H2'');\n',... ' >> quiz = sdmineq(quiz, [c4 1 2], Xindex, C2, 1);\n',... ' >> quiz = sdmineq(quiz, [c4 1 2], Sindex, E2, 1);\n',... ' >> quiz = sdmineq(quiz,[-c4 1 1], Tindex);\n',... ' >> quiz = sdmineq(quiz,[-c4 2 2], Xindex);\n',... ' >> [quiz,c5] = sdmlmi(quiz,1,''g<G1^2'');\n',... ' >> quiz = sdmineq(quiz, c5 , gindex);\n',... ' >> quiz = sdmineq(quiz, -c5 , 0 , G1);\n\n']); write5 = sprintf(['\nDECLARE OBJECTIVE (maximization)\n\n',... ' >> quiz = sdmobj(quiz,Tindex,''tr'',-1,''-trace(T)'')\n',... ' >> quiz = sdmobj(quiz,gindex,-1,1,''-g'')\n\n']); write=[write1,write2,write3,write4,write5]; fprintf('%s',write1); quiz = sdmpb('H2/Hinfty state-feedback synthesis'); fprintf('%s',write2); [quiz,Xindex] = sdmvar(quiz,n,'s','X'); [quiz,Tindex] = sdmvar(quiz,p2,'s','T'); [quiz,Sindex] = sdmvar(quiz,m,n,'S'); [quiz,gindex] = sdmvar(quiz,1,1,'g'); fprintf('%s',write3); [quiz,c1] = sdmlmi(quiz,n,'X>0'); quiz = sdmineq(quiz,-c1,Xindex); [quiz,c2] = sdmlmi(quiz,[n p1],'Hinf'); quiz = sdmineq(quiz, [c2 1 1], Xindex, A, 1); quiz = sdmineq(quiz, [c2 1 1], Sindex, B, 1); quiz = sdmineq(quiz, [c2 2 1], Xindex, C1, 1); quiz = sdmineq(quiz, [c2 2 1], Sindex, E1, 1); quiz = sdmineq(quiz, c2 , 0 , [B1;D1]); quiz = sdmineq(quiz,[-c2 2 2], gindex); [quiz,c3] = sdmlmi(quiz,n,'gram'); quiz = sdmineq(quiz, c3,Xindex,A,1); quiz = sdmineq(quiz, c3,Sindex,B,1); quiz = sdmineq(quiz, c3,0 ,B2); fprintf('%s',write4); [quiz,c4] = sdmlmi(quiz, [p2 n],'H2'); quiz = sdmineq(quiz, [c4 1 2], Xindex, C2, 1); quiz = sdmineq(quiz, [c4 1 2], Sindex, E2, 1); quiz = sdmineq(quiz,[-c4 1 1], Tindex); quiz = sdmineq(quiz,[-c4 2 2], Xindex); [quiz,c5] = sdmlmi(quiz,1,'g<G1^2'); quiz = sdmineq(quiz, c5,gindex); quiz = sdmineq(quiz,-c5,0 ,G1); fprintf('%s\n',write5); quiz = sdmobj(quiz,Tindex,'tr',-1,'-trace(T)'); quiz = sdmobj(quiz,gindex,-1,1,'-g'); fprintf('\n%s',next);pause;eval(next2); write1 = sprintf(['For details on every sdm*** function type ''help sdm***''\n\n',... 'Note that at each step it is possible ',... 'to have some information on the problem:\n\n',... '>> quiz']); write2 = sprintf(['It gives the name of the optimization problem,\n',... 'the number of matrix variables, their names and indexes,\n',... 'the number of inequality constraints, their names and indexes,\n',... 'the name of the linear objective.\n',... 'Moreover it is possible to get the structure of any matrix variable\n',... 'by giving its index as in:\n',... '>> quiz{Tindex}']); fprintf('%s\n',write1); quiz fprintf('%s\n',write2); quiz{Tindex} lT=size(quiz{Tindex},1); write3 = sprintf(['here T is a symmetric variable depending on %i decision variables\n',... 'numbered from %i to %i\n\n'],lT*(lT+1)/2,min(min(quiz{Tindex})),max(max(quiz{Tindex}))); fprintf('%s\n',write3); fprintf('\n%s',next);pause; clc;fprintf('%s\n\n',dotline); fprintf('%s\n',write1); quiz fprintf('%s\n',write2); quiz{Tindex} fprintf('%s\n',write3); fprintf('%s\n\n',dotline); fprintf('To solve this problem with SeDuMi:\n\n'); fprintf('>> quiz = sdmsol(quiz);\n\n'); quiz=sdmsol(quiz); fprintf('The variable <quiz> is appended and contains the solution\n\n'); fprintf('\n%s',next);pause; fprintf('\r%s\n\n',dotline); write1 = sprintf(['The obtained solution is the optimal point if the algorithm succeeded\n\n',... '>> quiz']); write2 = sprintf(['the display of the variable quiz (SDMPB object)\n',... 'informs on the status of the optimization problem.\n',... 'It gives for each inequality constraint the minimal eigenvalue\n',... '(the constraint is exactly satisfied if meig>=0)\n',... '(if meig=-eps or +eps then close to zero at the accuracy level)\n',... 'and the optimal objective value\n\n']); fprintf('%s\n',write1); quiz fprintf('%s\n',write2); fprintf('\n%s',next);pause; clc;fprintf('%s\n\n',dotline); fprintf('%s\n',write1); quiz fprintf('%s\n',write2); fprintf('%s\n\n',dotline); write1 = sprintf(['Moreover the values of the variables for the obtained point\n',... 'are easily obtained: \n\n',... '>> Sopt=quiz(Sindex)']); write2 = sprintf(['contains the optimal value of S \n\n',... '>> Topt=quiz(Tindex);\n',... '>> sqrt(trace(Topt)))']); write3 = sprintf(['gives the guaranteed H2 norm (sqrt(trace(T)))\n\n',... '>> gopt=quiz(gindex)\n',... '>> sqrt(gopt)']); write4 = sprintf('gives the guaranteed Hinfty norm (sqrt(g))\n\n'); fprintf('%s\n',write1); Sopt=quiz(Sindex) fprintf('%s\n',write2); sqrt(trace(quiz(Tindex))) fprintf('%s\n',write2); sqrt(quiz(gindex)) fprintf('%s\n',write4); fprintf('\n%s',next);pause; clc;fprintf('%s\n\n',dotline); fprintf('%s\n',write1); Sopt=quiz(Sindex) fprintf('%s\n',write2); sqrt(trace(quiz(Tindex))) fprintf('%s\n',write2); sqrt(quiz(gindex)) fprintf('%s\n',write4); fprintf('%s\n\n',dotline); write = sprintf(['Consider that the H2/Hinfty problem is modified such that:\n\n',... 'the minimization of the variable g is suppressed.\n\n',... 'One way to change the problem is to set in the LMIs: g=G1^2\n\n',... ' >> quiz = sdmset(quiz,gindex,G1^2)\n\n']); quiz = sdmset(quiz,gindex,G1^2) eval(next1);eval(next2); write = sprintf(['The new problem can then be solved.\n\n',... '>> quiz = sdmsol(quiz);\n\n']); fprintf('%s\n',write); quiz=sdmsol(quiz); fprintf('\n%s',next);pause; fprintf('\r%s\n\n',dotline); fprintf('The obtained solution is the optimal point if the algorithm succeeded\n\n'); fprintf('>> quiz'); quiz fprintf('>> Topt=quiz(Tindex);\n'); fprintf('>> sqrt(trace(Topt)))'); sqrt(trace(quiz(Tindex))) fprintf('gives the guaranteed H2 norm (sqrt(trace(T)))\n\n'); end; fprintf('\n\n -- end of demo - thanks -- \n\n');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -