您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > Matlab内置的约束优化函数用法
约束优化-Matlabfmincon•helpfmincon•docfmincon•typefmincon•Editfmincon•x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)Karush-Kuhn-Tucker(KKT)conditions例1线性约束fminconlinprog也可解此类问题lingprogf=[53];A=[53;-1-1;-10;0-1];b=[70;-15;-5;0];x0=[0;0];[x,fval]=linprog(f,A,b,[],[],[],[],x0)x=linprog(f,A,b,Aeq,beq,lb,ub,x0)f=[53];A=[53;-1-1];b=[70;-15];x0=[0;0];lb=[5;0];[x,fval]=linprog(f,A,b,[],[],lb,[],x0)x=linprog(f,A,b,Aeq,beq,lb,ub,x0)functionf=ros(x)f=5*x(1)+3*x(2);A=[53;-1-1];b=[70;-15];x0=[0;0];lb=[5;0];[x,fval]=fmincon(@ros,x0,A,b,[],[],lb)x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)例2:Rosenbrock‘sFunction非线性约束fmincons.t.x=fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@mycon)wheremyconisaMATLABfunctionsuchasfunction[c,ceq]=mycon(x)c=...%Computenonlinearinequalitiesatx.ceq=...%Computenonlinearequalitiesatx.•functionf=rosenbrock(x)•f=100*(x(2)-x(1)^2)^2+(1-x(1))^2;•function[c,ceq]=unitdisk(x)•c=x(1)^2+x(2)^2-1;•ceq=[];function[c,ceq]=mycon(x)c=...%Computenonlinearinequalitiesatx.ceq=...%Computenonlinearequalitiesatx.x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)options=optimset('Display','iter','Algorithm','active-set');[x,fval]=fmincon(@rosenbrock,[00],...[],[],[],[],[],[],@unitdisk,options)[x,fval]=fmincon(@rosenbrock,[00],[],[],[],[],[],[],@unitdisk)例3线性和非线性约束fminconx=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)例4ConstrainedMinimizationUsingpatternsearchpatternsearchfunctiony=simple_objective(x)y=(4-2.1*x(1)^2+x(1)^4/3)*x(1)^2+x(1)*x(2)+(-4+4*x(2)^2)*x(2)^2;function[c,ceq]=simple_constraint(x)c=[1.5+x(1)*x(2)+x(1)-x(2);-x(1)*x(2)+10];ceq=[];ObjectiveFunction=@simple_objective;X0=[00];%StartingpointLB=[00];%LowerboundUB=[113];%UpperboundConstraintFunction=@simple_constraint;[x,fval]=patternsearch(ObjectiveFunction,X0,[],[],[],[],...LB,UB,ConstraintFunction)options=psoptimset('PlotFcns',{@psplotbestf,@psplotmaxconstr},'Display','iter');[x,fval]=patternsearch(ObjectiveFunction,X0,[],[],[],[],LB,UB,ConstraintFunction,options)
本文标题:Matlab内置的约束优化函数用法
链接地址:https://www.777doc.com/doc-5726590 .html