您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > Matlab帐篷M文件优化代码
%绘制原始帐篷的顶柱largel=zeros(36);mask=[673031];largel(mask,mask)=.3*ones(4);largel(18:19,18:19)=.5*ones(2);xx=[1:5,5:6,6:15,15:16,16:25,25:26,26:30];[XX,YY]=meshgrid(xx);axis([1301300.5],'off');surface(XX,YY,largel,'facecolor',[.5.5.5],'edgecolor','none');light;colormap(gray);view([-20,30]);title('Thesetoftentpoles');%下限约束表面L=zeros(30);E=ones(2);L(15:16,15:16)=.5*E;L(5:6,5:6)=.3*E;L(25:26,5:6)=.3*E;L(5:6,25:26)=.3*E;L(25:26,25:26)=.3*E;%visualizetheconstraint%AddLtotheplot.surface(L,'facecolor','none','edgecolor','m');title('LowerBoundConstraintSurface');%设置帐篷的优化初始值,并可视化sstart=.5*ones(30,30);%Addittotheplotsurface(sstart,'FaceColor','none','LineStyle','none','Marker','.','MarkerEdgeColor','blue');title('InitialValue(blue)andLowerBound(magenta)');set(gcf,'renderer','zbuffer');%向量转换low=reshape(L,900,1);xstart=reshape(sstart,900,1);xx=0:4;[X,Y]=meshgrid(xx,xx);gpts=plot(X(:),Y(:),'b.');set(gpts,'markersize',10);axisoff;axis([-212-1.55.5]);holdon;l(1)=line([7.56.5],[22.5]);l(2)=line([7.56.5],[21.5]);l(3)=line([7.55.5],[22]);set(l,'color','b');yy=0.2*xx;zz=[-1.5+yy,yy,1.5+yy,3+yy,4.5+yy];vect=plot(9*ones(25,1),zz,'b');set(vect,'markersize',9);axisoff;holdoff;%绘制目标能量函数H=delsq(numgrid('S',30+2));h=1/(30-1);c=-h^2*ones(30^2,1);%查看矩阵结构spy(H);title('StructureofHessianMatrix');%绘制数据点的相对位置loadtentdata;plot(xXX3,XX3,'b.',xXX1,XX1,'r.',xXX2,XX2,'r.');set(gca,'YTick',[-11]);set(gca,'YTickLabel',{'lower';'upper'});axis([1900-11]);title('Relativepositionofx(i)toupperandlowerbounds(log-scale)');%归一化相对梯度currplot=plot(xGG2,GG2,'b.',xGG1,GG1,'r.');title('Relativegradientscaledtotherange-1to1');legend('abs(grad)tol','abs(grad)=tol',4);axis([1900-11]);set(gca,'YTick',[-101]);ylabel('gradient');%优化求解options=optimset('LargeScale','on','display','off');x=quadprog(H,c,[],[],[],[],low,[],xstart,options);%利用优化结果绘制曲面图S=reshape(x,30,30);delete(findobj(0,'Name','AlgorithmPerformanceStatistics'));delete(findobj(0,'Name','ProgressInformation'));subplot(1,2,1);surf(L,'facecolor',[.5.5.5]);surface(sstart,'edgecolor','b','facecolor','none');title('StartingSurface');axisoffaxistight;view([-20,30]);subplot(1,2,2);surf(L,'facecolor',[.5.5.5]);surface(S,'edgecolor','b','facecolor','none');title('SolutionSurface');axisoffaxistight;view([-20,30]);%设置帐篷属性subplot(1,1,1);surf(L,'facecolor',[000]);holdonsurfl(S);holdoff;axistight;axisoff;view([-20,30]);示意图:
本文标题:Matlab帐篷M文件优化代码
链接地址:https://www.777doc.com/doc-5920878 .html