I used the PENLAB to solve. However, the iteration output is
The following figure is the right answer. The corresponding color in the two colormap is different but the whole color gamut is same.
%%********************************************************************% linear SDP but slow and huge% min(E) sum(trace(E_i))% s.t. Ei>=0% l<= trace(E_i) <=u% [gamma, f^T; f, A(E)]>=0%%********************************************************************dbstop if errorclear allyalmip('clear')
nelx = 20;nely = 10;m = nelx*nely;l = 1e-4;u = 1;gamma = 170;
% ======================= FEA ==========================================fixeddofs = 1:2*(nely+1);alldofs = 2*(nely+1)*(nelx+1);freedofs = setdiff(1:alldofs,fixeddofs);
% loadnid = 2*(nely+1)*(nelx+1);loadnid = (nely+1)*nelx+1+(nely+1)*(nelx+1);F = sparse(loadnid,1,-1,alldofs,1);
% for assmble nodenrs = reshape(1:(1+nelx)*(1+nely),1+nely,1+nelx);edofVec = reshape(2*nodenrs(1:end-1,1:end-1)+1,m,1);edofMat = repmat(edofVec,1,8)+repmat([0 1 2*nely+[2 3 0 1] -2 -1],m,1);iK = reshape(kron(edofMat,ones(8,1)).',64*m,1);jK = reshape(kron(edofMat,ones(1,8)).',64*m,1);
%============================== FMO ===============================ops = sdpsettings('solver','sdpt3');ops.showprogress = 1; %1为设置显示yalmip现在在做什么ops.verbose = 2; %设置显示信息程度,1为适度显示,2为完全显示。ops.debug = 1;
trE = 0;cons1 = [];cons2 = [];for i = 1:m E{i} = sdpvar(3); % 3*3 symmetric assign(E{i},repmat(0.1*u,3,3)); cons2 = [cons2,E{i} >= 0]; % constraint 2: Ei>=0 cons1 = [cons1,l<= trace(E{i}) <=u]; % constraint 1: l<= trace(E_i) <=u
trE = trE+trace(E{i}); tempE = E{i}; sE(:,i) = [tempE(1,1);tempE(1,2);tempE(1,3);tempE(2,2);tempE(2,3);tempE(3,3)];endsK = getK(sE);K = sparse(iK,jK,sK);K = (K+K')/2;
% constraint 3: [gamma, f^T; f, A(E)]>=0cons3 = [gamma,F';F,K] >= 0; obj = trE;sol = optimize([cons1,cons2,cons3],obj,ops);
>> sdpvar gamma>> optimize([cons1,cons2,[gamma F';F K]>=0])
>> eig(value([gamma F';F K]))
ans =
-8.965346389965378e-09 -2.197306043384670e-12 -1.411122297642595e-13 2.824596349326144e-03 5.866168694096923e-03
...
optimize([cons1,cons2,[gamma F';F K]>=0],gamma)
>> eig(value([gamma F';F K]))
ans =
-1.895104879418130e-07 -3.988447448666848e-14 7.432205916707894e-13 2.355337978541212e-03
>> assign(gamma,1e32);>> min(eig(value([gamma F';F K])))
ans =
-3.053257919279714e+16