《Matlab内置的约束优化函数用法课件》由会员分享,可在线阅读,更多相关《Matlab内置的约束优化函数用法课件(25页珍藏版)》请在金锄头文库上搜索。
1、约束优化-Matlabfminconhelp fmincondoc fmincontype fminconEdit fminconx = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)Karush-Kuhn-Tucker (KKT) conditions例1 线性约束fmincon linprog也可解此类问题lingprogf=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,x
2、0)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: Rosenbrocks Function非线性约束fmincon
3、s.t.x = fmincon(myfun,x0,A,b,Aeq,beq,lb,ub,mycon)where mycon isa MATLAB function such asfunction 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
4、)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
5、 = fmincon(rosenbrock,0 0, ,unitdisk)例3 线性和非线性约束 fminconx = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)例4Constrained Minimization Using patternsearchpatternsearchfunction 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_cons
6、traint(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 pointLB = 0 0; % Lower boundUB = 1 13; % Upper boundConstraintFunction = 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)