matlab条件约束优化函数,Matlab内置的约束优化函数用法.ppt

Matlab内置的约束优化函数用法

约束优化-Matlab fmincon help fmincon doc fmincon type fmincon Edit fmincon x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options) Karush-Kuhn-Tucker (KKT) conditions 例1 线性约束fmincon linprog也可解此类问题 lingprog f=[5 3]; A=[5 3;-1 -1;-1 0;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=[5 3]; A=[5 3;-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) function f=ros(x) f=5*x(1) + 3*x(2); A=[5 3;-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‘s Function非线性约束fmincon s.t. x = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@mycon) where mycon is a MATLAB function such as function [c,ceq] = mycon(x) c = ... % Compute nonlinear inequalities at x. ceq = ... % Compute nonlinear equalities at x. function f = 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 = ... % Compute nonlinear inequalities at x. ceq = ... % Compute nonlinear equalities at x. x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options) options = optimset('Display','iter','Algorithm','active-set'); [x,fval] = fmincon(@rosenbrock,[0 0],... [],[],[],[],[],[],@unitdisk,options) [x,fval] = fmincon(@rosenbrock,[0 0], [],[],[],[],[],[],@unitdisk) 例3 线性和非线性约束 fmincon x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options) 例4Constrained Minimization Using patternsearchpatternsearch function y = 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 = [0 0]; % Starting point LB = [0 0]; % Lower bound UB = [1 13]; % Upper bound ConstraintFunction = @simple_constraint; [x,fva

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值