用Matlab求解非线性约束优化问题 本文将介绍如何在Matlab中用序列二次规划法求解非线性约束优化问题。Matlab 方法/步骤 1 求解题目如下: 2 根据题目建立目标函数文件: 3 建立非线性约束函数文件: 。
用matlab求解一个优化问题(目标函数非线性,约束函数线性) 程序编的非常好,只有一句:size(x)=[4,3]改为x=zeros(4,3)即可。function fffclear;clc;A=[1,1,1,0,0,0,0,0,0,0,0,0;0,0,0,1,1,1,0,0,0,0,0,0;0,0,0,0,0,0,1,1,1,0,0,0;0,0,0,0,0,0,0,0,0,1,1,1;1,0,0,-1,0,0,-1,0,0,-1,0,0;0,-1,0,0,-1,0,0,-1,0,0,-1,0;0,0,-1,0,0,-1,0,0,-1,0,0,-1]b=[200-1.645*10;300-1.645*10;400-1.645*10;200-1.645*10;100-1.645*10;300-1.645*10;400-1.645*10]x0=[0,0,0,0,0,0,0,0,0,0,0,0];lb=[0,0,0,0,0,0,0,0,0,0,0,0];ub=[];[X,FVAL,EXITFLAG]=fmincon(@myobj,x0,A,b,[],[],lb,ub)function f=myobj(x)c=[12 21 21;13 20 23;15 17 27;17 19 31];x=zeros(4,3)y=c.*x;y=sum(y(:));s=0;for i=1:4sg=sum(x(i,:));s=s+sg.^0.6;endf=y+200*s;运行结果:X=19.5167 69.5167 94.5167 38.7083 88.7083 113.7083 38.7083 88.7083 113.7083 19.5167 69.5167 94.5167FVAL=0EXITFLAG=1
matlab 非线性约束最优化问题,希望给出代码 先建立M文件fun.m定义目标函数:function f=fun(x)f=((x(1)+1)^2+4*(x(2)-1.5)^2)*((x(1)-1.2)^2+0.4*(x(2)-0.5)^2);再建立M文件mycon.m定义非线性约束:function[g,ceq]=mycon(x)g=[2*x(1)-x(1)*x(2)+5*x(2)-6;x(1)-x(2)+0.5;x(1)^2-4*x(2)^2+x(2)];ceq=0;主程序为:x0=[0;0];VLB=[0 0];VUB=[];[x,fval,exitflag,output]=fmincon('fun',x0,[],[],[],[],VLB,VUB,'mycon2')结果为:x=0.59251.0925fval=1.6306exitflag=1output=iterations:5funcCount:18lssteplength:1stepsize:8.6939e-007algorithm:'medium-scale:SQP,Quasi-Newton,line-search'firstorderopt:3.2838e-008constrviolation:1.6077e-011message:[1x144 char]