概述
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
最后
以上就是谨慎毛豆为你收集整理的matlab条件约束优化函数,Matlab内置的约束优化函数用法.ppt的全部内容,希望文章能够帮你解决matlab条件约束优化函数,Matlab内置的约束优化函数用法.ppt所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复