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

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

patternsearch
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 = [];
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.
ObjectiveFunction = @simple_objective; X0 = [0 0]; % Starting point LB = [0 0]; % Lower bound UB = [1 13]; % Upper bound ConstraintFunction = @simple_constraint; [x,fval] = patternsearch(ObjectiveFunction,X0,[],[],[],[],... LB,UB,ConstraintFunction)
Fra Baidu bibliotek
options = psoptimset('PlotFcns',{@psplotbestf,@psplotmaxconstr},'Display','ite r'); [x,fval] = patternsearch(ObjectiveFunction,X0,[],[],[],[],LB,UB,ConstraintFunct ion,options)
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);
约束优化-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
[x,fval] = fmincon(@rosenbrock,[0 0], [],[],[],[],[],[],@unitdisk)
例3 线性和非线性约束 fmincon
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
例4 Constrained Minimization Using patternsearch
例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)
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
• 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)
相关文档
最新文档