⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdmset.m

📁 这是matlab解2阶锥工具包
💻 M
字号:
function quiz = sdmset(quiz,Xindex,varvalu)% SDMPB/SDMSET - set a value to some variable and modify the LMC problem%   % quiz = sdmset(quiz,Xindex,Xvalue);%  % Remove the matrix variable specified by Xindex% and modify subsequently the constant term of the LMI and LME constraints. % The constraints depending only on this variable are removed. % Note that the indexes of the variables and constraints are not modified.%% SEE ALSO sdmvar, sdmlmi, sdmlme, sdmobj and sdmsol.%   This file is part of SeDuMi Interface 1.04 (JUL2002)%   Last Update 10th September 2002%   Copyright (C) 2002 Dimitri Peaucelle & Krysten Taitz%   LAAS-CNRS, Toulouse, France% %   This program is free software; you can redistribute it and/or modify%   it under the terms of the GNU General Public License as published by%   the Free Software Foundation; either version 2 of the License, or%   (at your option) any later version.% %   This program is distributed in the hope that it will be useful,%   but WITHOUT ANY WARRANTY; without even the implied warranty of%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%   GNU General Public License for more details.% %   You should have received a copy of the GNU General Public License%   along with this program; if not, write to the Free Software%   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.       %%% check inputs  if nargin<3    error('not enough input arguments');  elseif nargin>3    error('too many input arguments');  elseif ~isa(quiz,'sdmpb')    error('1st input argument must be a SDMPB object');  elseif ( ~isnumeric(Xindex) ...	   | round(Xindex)~=Xindex ...	   | any(size(Xindex)-[1,1]) ...	   | Xindex<=0 )    error('2nd input argument (index of the variable) must be a positive integer');  elseif Xindex>quiz.var.nb    error('2nd input argument (index of the variable) exceeds the number of variables');  elseif ~isnumeric(varvalu)    error('3rd input argument (value set to the variable) must be a matrix');  end;        %%% define useful fields  varm=quiz.var.m(Xindex);  varM=quiz.var.M(Xindex);  varrow=quiz.var.row(Xindex);  varcol=quiz.var.col(Xindex);  %%% check the value to set has the correct dimensions  if any(size(varvalu)-[varrow,varcol])    error('3rd input argument (set value) has wrong dimensions')  end;  %%% check that the given value fits the variable structure  % some manipulations  indexvardec = find(max(abs(quiz.var.struc(varm:varM,:)),[],1));  strucX=quiz.var.struc(varm:varM,indexvardec);  strucconjX=quiz.var.strucconj(varm:varM,indexvardec);  varvalu=sdmvec(varvalu);  % first for the real part of the variable  if norm(real(varvalu),1)    if sdmrank([strucX+strucconjX real(varvalu)])~=sdmrank(strucX+strucconjX)      error(['The real part of the 3rd input argument (set value) does not fit the variable structure']);        end;  end;  % second for the imaginary part of the variable  if norm(imag(varvalu),1)    if sdmrank([strucX-strucconjX imag(varvalu)])~=sdmrank(strucX-strucconjX)      error(['The imaginary part of the 3rd input argument (set value) does not fit the variable structure']);        end;  end;  %%% clear the previous solution if necessary  quiz = sdmclear(quiz);  %%% eliminating all references to the variable  quiz.var.m((Xindex+1):end)=quiz.var.m((Xindex+1):end)-(varM-varm+1);  quiz.var.M(Xindex:end)=quiz.var.M(Xindex:end)-(varM-varm+1);  quiz.var.row(Xindex)=0;  quiz.var.col(Xindex)=0;  quiz.var.name{Xindex}=[quiz.var.name{Xindex},' SET TO A CONSTANT'];   quiz.var.set{Xindex}=varvalu;  %%% defining the matrix variables we keep  keepmatvar=[1:(varm-1),(varM+1):size(quiz.var.struc,1)];  %%% elimination on the structure matrices  struc=quiz.var.struc;  quiz.var.struc=struc(keepmatvar,:);  strucconj=quiz.var.strucconj;  quiz.var.strucconj=strucconj(keepmatvar,:);  %%% elimination of non-existing decision variables  oldvardecnb=get(quiz,'vardecnb');  allstruc=[quiz.var.struc;quiz.var.strucconj];  keepvar=find(max(abs(allstruc),[],1));  newstruc=quiz.var.struc(:,keepvar);  newstrucconj=quiz.var.strucconj(:,keepvar);  quiz.var.struc=newstruc;  quiz.var.strucconj=newstrucconj;  newycomplex=sparse(quiz.K.ycomplex,1,1,oldvardecnb,1);  newycomplex=newycomplex(keepvar);  quiz.K.ycomplex=find(newycomplex);    %%% elimination on the objective   bt=quiz.obj.bt;  quiz.obj.bt=bt(:,keepmatvar);  btconj=quiz.obj.btconj;  quiz.obj.btconj=btconj(:,keepmatvar);  %%% elimination on the LMI constraints  %%% add the new constant term  c=quiz.ineq.c;  At=quiz.ineq.At;  Atconj=quiz.ineq.Atconj;  quiz.ineq.c=c-At(:,varm:varM)*varvalu;  %%% elimination on the variable dependent terms  quiz.ineq.At=At(:,keepmatvar);  quiz.ineq.Atconj=Atconj(:,keepmatvar);  %%% eliminating inconsistent LMI constraints  for ii=1:quiz.ineq.nb    lmim=quiz.ineq.m(ii);    lmiM=quiz.ineq.M(ii);    c=quiz.ineq.c;    At=quiz.ineq.At;    Atconj=quiz.ineq.Atconj;    At=At(lmim:lmiM,:);    Atconj=Atconj(lmim:lmiM,:);    if (~norm(At,1) & ~norm(Atconj,1))      c=c(lmim:lmiM,:);          C=sdmmat(c);      C=C+C';      if min(real(eig(C)))<0	warning(sprintf([...	    'the 3rd input argument (variable''s value) \n'...	    'does not satisfy the inequality constraint number: %i'],ii));      end;            quiz.ineq.name{ii}=[quiz.ineq.name{ii} ' REMOVED'];      quiz.ineq.meig{ii}=0;      dim=lmiM-lmim+1;      quiz.ineq.m(ii+1:end)=quiz.ineq.m(ii+1:end)-dim;      quiz.ineq.M(ii:end)=quiz.ineq.M(ii:end)-dim;            keepineq=[1:(lmim-1),(lmiM+1):size(quiz.ineq.c,1)];      quiz.ineq.c=quiz.ineq.c(keepineq);      quiz.ineq.At=quiz.ineq.At(keepineq,:);      quiz.ineq.Atconj=quiz.ineq.Atconj(keepineq,:);      quiz.K.s(ii)=0;    end;  end;  %%% elimination on the LME constraints  %%% add the new constant term  c=quiz.eq.c;  At=quiz.eq.At;  Atconj=quiz.eq.Atconj;  quiz.eq.c=c-(At(:,varm:varM)+Atconj(:,varm:varM))*varvalu;  %%% elimination on the variable dependent terms  quiz.eq.At=At(:,keepmatvar);  quiz.eq.Atconj=Atconj(:,keepmatvar);  %%% eliminating inconsistent LME constraints  for ii=1:quiz.eq.nb    lmem=quiz.eq.m(ii);    lmeM=quiz.eq.M(ii);    c=quiz.eq.c(lmem:lmeM,:);    At=quiz.eq.At(lmem:lmeM,:);    Atconj=quiz.eq.Atconj(lmem:lmeM,:);    if (~norm(At,1) & ~norm(Atconj,1))      if norm(c,1)>eps	warning(sprintf([...	    'the 3rd input argument (variable''s value) \n'...	    'does not satisfy the equality constraint number: %i'],ii));      end;            quiz.eq.name{ii}=[quiz.eq.name{ii} ' REMOVED'];      quiz.eq.mnorm{ii}=0;      dim=lmeM-lmem+1;      quiz.eq.m((ii+1):end)=quiz.eq.m((ii+1):end)-dim;      quiz.eq.M(ii:end)=quiz.eq.M(ii:end)-dim;            keepeq=[1:(lmem-1),(lmeM+1):size(quiz.eq.c,1)];      quiz.eq.c=quiz.eq.c(keepeq);      quiz.eq.At=quiz.eq.At(keepeq,:);      quiz.eq.Atconj=quiz.eq.Atconj(keepeq,:);    end;  end;      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -