cd V:\Cursos\Pos\Otimiza\Aulas type ex_qp1 % min S(x) = 4 * x1^2 + 5 * x2^2 % s.a. h(x) = 2 * x1 + 3 * x2 - 6 = 0 % % x' = [1.071 1.286] Q=[4 0;0 5]*2 c=[0; 0] A=[] b=[] Aeq=[2 3] beq=6 lb=[] ub=[] op=optimset('LargeScale','off'); [x,s,ex,out,lambda]=quadprog(Q,c,A,b,Aeq,beq,lb,ub,[],op) Al=[Aeq 0 0 0;Q Aeq' -eye(2)] bl=[beq;0;0] cl=0.5*[0;0;-beq;0;0] LB=[0;0;-Inf;-Inf;-Inf]; UB=[Inf;Inf;0;0;0]; [X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=LINPROG(cl,[],[],Al,bl,LB,UB,[],op) Q=[4 0;0 5]*2 Q = 8 0 0 10 c=[0; 0] c = 0 0 A=[] A = [] b=[] b = [] Aeq=[2 3] Aeq = 2 3 beq=6 beq = 6 lb=[] lb = [] ub=[] ub = [] op=optimset('LargeScale','off'); [x,s,ex,out,lambda]=quadprog(Q,c,A,b,Aeq,beq,lb,ub,[],op) Optimization terminated successfully. x = 1.0714 1.2857 s = 12.8571 ex = 1 out = iterations: 1 algorithm: 'medium-scale: active-set' firstorderopt: [] cgiterations: [] lambda = lower: [2x1 double] upper: [2x1 double] eqlin: -4.2857 ineqlin: [0x1 double] ex_qp1 Q = 8 0 0 10 c = 0 0 A = [] b = [] Aeq = 2 3 beq = 6 lb = [] ub = [] Optimization terminated successfully. x = 1.0714 1.2857 s = 12.8571 ex = 1 out = iterations: 1 algorithm: 'medium-scale: active-set' firstorderopt: [] cgiterations: [] lambda = lower: [2x1 double] upper: [2x1 double] eqlin: -4.2857 ineqlin: [0x1 double] Al = 2 3 0 0 0 8 0 2 -1 0 0 10 3 0 -1 bl = 6 0 0 cl = 0 0 -3 0 0 Optimization terminated successfully. X = 1.0714 1.2857 -4.2857 0 0 FVAL = 12.8571 EXITFLAG = 1 OUTPUT = iterations: 2 algorithm: 'medium-scale: activeset' firstorderopt: [] cgiterations: [] LAMBDA = lower: [5x1 double] upper: [5x1 double] eqlin: [3x1 double] ineqlin: [0x1 double] type ex_qp2 % min S(x) = (x1^2 + x2^2 + x3^2)/2 % s.a. g1(x) = 3/2 - x1 - x2 <= 0 % g2(x) = x1 - x3 -1 <= 0 % g3(x) = x2 + x3 - 2/5 <= 0 % % x' = [0.833 0.633 -0.2] (melhor solucao inviavel, no sentido de minimos quadrados) % x1' = [0.7667 0.5833 -0.1833] Q=[1 0 0;0 1 0;0 0 1] c=[0; 0; 0] A=[-1 -1 0 1 0 -1 0 1 1] b=[-3/2; 1; 2/5] Aeq=[] beq=[] lb=[] ub=[] [x,s,ex,out,lambda]=quadprog(Q,c,A,b,Aeq,beq,lb,ub) b1=[-3/2*0.9; 1; 2/5] [x1,s1,ex,out,lambda1]=quadprog(Q,c,A,b1,Aeq,beq,lb,ub) ex_qp2 Q = 1 0 0 0 1 0 0 0 1 c = 0 0 0 A = -1 -1 0 1 0 -1 0 1 1 b = -1.5000 1.0000 0.4000 Aeq = [] beq = [] lb = [] ub = [] Exiting: The constraints are overly stringent; no feasible starting point found. x = 0.8333 0.6333 -0.2000 s = 0.5678 ex = -1 out = iterations: 0 algorithm: 'medium-scale: active-set' firstorderopt: [] cgiterations: [] lambda = lower: [3x1 double] upper: [3x1 double] eqlin: [0x1 double] ineqlin: [3x1 double] b1 = -1.3500 1.0000 0.4000 Optimization terminated successfully. x1 = 0.7667 0.5833 -0.1833 s1 = 0.4808 ex = 1 out = iterations: 3 algorithm: 'medium-scale: active-set' firstorderopt: [] cgiterations: [] lambda1 = lower: [3x1 double] upper: [3x1 double] eqlin: [0x1 double] ineqlin: [3x1 double] type ex_qp3 % min S(x) = x1^2 + x2^2 + x3^2 (problema super restrito) % s.a. g1(x) = 2 * x1 + x2 - 5 <= 0 % g2(x) = x1 + x3 - 2 <= 0 % g3(x) = x1 + 2 * x2 + x3 - 10 <= 0 % h1(x) = 2 * x1 - 2 * x2 + x3 + 2 = 0 % h2(x) = 10 * x1 + 8 * x2 - 14 * x3 - 26 = 0 % h3(x) = -4 * x1 + 5 * x2 - 6 * x3 - 6 = 0 % x1 >= 1, x2 >= 2, x3 >= 0 % % x' =[1 2 0] Q=[1 0 0;0 1 0;0 0 1]*2 c=[0; 0; 0] A=[2 1 0 1 0 1 1 2 1] b=[5; 2; 10] Aeq=[ 2 -2 1 10 8 -14 -4 5 -6] beq=[-2; 26; 6] lb=[1; 2; 0] ub=[] op=optimset('LargeScale','off'); [x,s,ex,out,lambda]=quadprog(Q,c,A,b,Aeq,beq,lb,ub,[],op) % removendo as restricoes de igualdade Aeq1=[] beq1=[] [x1,s1,ex,out,lambda1]=quadprog(Q,c,A,b,Aeq1,beq1,lb,ub,[],op) % mudando a funcao objetivo c2=[-1;0;-3] [x2,s2,ex,out,lambda2]=quadprog(Q,c2,A,b,Aeq1,beq1,lb,ub,[],op) % mudando o limite inferior lb3=zeros(3,1); [x3,s3,ex,out,lambda3]=quadprog(Q,c2,A,b,Aeq1,beq1,lb3,ub,[],op) % resolvendo o ultimo caso como LP Al=[A eye(3) zeros(3) zeros(3);Q zeros(3) A' -eye(3)] bl=[b;-c2] cl=0.5*[c2;zeros(3,1);-b;zeros(3,1)] LB=[zeros(6,1);-Inf*ones(6,1)]; UB=[Inf*ones(6,1);zeros(6,1)]; op=optimset('LargeScale','off'); [X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=LINPROG(cl,[],[],Al,bl,LB,UB,[],op) ex_qp3 Q = 2 0 0 0 2 0 0 0 2 c = 0 0 0 A = 2 1 0 1 0 1 1 2 1 b = 5 2 10 Aeq = 2 -2 1 10 8 -14 -4 5 -6 beq = -2 26 6 lb = 1 2 0 ub = [] Optimization terminated successfully. x = 1.0000 2.0000 0.0000 s = 5.0000 ex = 1 out = iterations: 0 algorithm: 'medium-scale: active-set' firstorderopt: [] cgiterations: [] lambda = lower: [3x1 double] upper: [3x1 double] eqlin: [3x1 double] ineqlin: [3x1 double] Aeq1 = [] beq1 = [] Optimization terminated successfully. x1 = 1 2 0 s1 = 5 ex = 1 out = iterations: 3 algorithm: 'medium-scale: active-set' firstorderopt: [] cgiterations: [] lambda1 = lower: [3x1 double] upper: [3x1 double] eqlin: [0x1 double] ineqlin: [3x1 double] c2 = -1 0 -3 Optimization terminated successfully. x2 = 1 2 1 s2 = 2 ex = 1 out = iterations: 3 algorithm: 'medium-scale: active-set' firstorderopt: [] cgiterations: [] lambda2 = lower: [3x1 double] upper: [3x1 double] eqlin: [0x1 double] ineqlin: [3x1 double] Optimization terminated successfully. x3 = 0.5000 0 1.5000 s3 = -2.5000 ex = 1 out = iterations: 1 algorithm: 'medium-scale: active-set' firstorderopt: [] cgiterations: [] lambda3 = lower: [3x1 double] upper: [3x1 double] eqlin: [0x1 double] ineqlin: [3x1 double] Al = 2 1 0 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 2 1 0 0 1 0 0 0 0 0 0 2 0 0 0 0 0 2 1 1 -1 0 0 0 2 0 0 0 0 1 0 2 0 -1 0 0 0 2 0 0 0 0 1 1 0 0 -1 bl = 5 2 10 1 0 3 cl = -0.5000 0 -1.5000 0 0 0 -2.5000 -1.0000 -5.0000 0 0 0 Optimization terminated successfully. X = 0.5000 0.0000 1.5000 4.0000 0.0000 8.0000 0.0000 -0.0000 0.0000 0.0000 0.0000 0 FVAL = -2.5000 EXITFLAG = 1 OUTPUT = iterations: 6 algorithm: 'medium-scale: activeset' firstorderopt: [] cgiterations: [] LAMBDA = lower: [12x1 double] upper: [12x1 double] eqlin: [6x1 double] ineqlin: [0x1 double] eig([1 1;1 1]) ans = 0 2.0000 what M-files in the current directory V:\Cursos\Pos\Otimiza\Aulas CATALIS fmincon1 minlp1 swarm EXTRATOR fminunc1 minlp2 test0 LUCRO fminusub minlp3 test1 MINQUA fun minlp4 test10 MODELO func44 minlp5 test11 Minqua44 gmilp1 minlp6 test12 Modelo44 gminlp1 minlpn test13 OPT_RES gminlp2 modelagem test14 PLANOS gminlp3 naturais test15 READ2 gminlp4 newton test16 SEMIDEF gminlp5 newton_h test17 SMODELO gminlp6 newton_mod test18 aurea gmodelagem newtont test19 bandem1 gmurray nlconst test1gn bfgs grad nlp_internal test1m bracket grg pareto18 test2 buscarnd gtest1 pareto19 test20 cgrad gtest10 pareto20 test21 checkbounds gtest12 pareto21 test22 coggins gtest13 powell test23 compdir gtest2 qpsub test3 complex gtest8 refino test4 dados_ex6_44 gtest9 restr test5 dfp hkjeeves restr1 test6 dual htest1 restr14 test7 ex2_karm htest10 restr15 test8 ex_karma htest2 restr16 test9 ex_qp1 htest9 restr17 teste_buscarnd ex_qp2 interior restr20 univar ex_qp3 karmarkar restr21 varmetr ex_swarm lmarqua rosembr visual exmilp lp_nlp set1 writearq exmilp2 milp setoptim xplot exmilprog milp1 sol_extrat exmilprog2 milprog sqp extrat minlp steepdes semidef opt_res ??? Input argument 'x' is undefined. Error in ==> V:\Cursos\Pos\Otimiza\Aulas\OPT_RES.M On line 3 ==> S=x(1)^2+x(2)^2-3*x(1)+15*x(2); ex_qp1 Q = 8 0 0 10 c = 0 0 A = [] b = [] Aeq = 2 3 beq = 6 lb = [] ub = [] Optimization terminated successfully. x = 1.0714 1.2857 s = 12.8571 ex = 1 out = iterations: 1 algorithm: 'medium-scale: active-set' firstorderopt: [] cgiterations: [] lambda = lower: [2x1 double] upper: [2x1 double] eqlin: -4.2857 ineqlin: [0x1 double] Al = 2 3 0 0 0 8 0 2 -1 0 0 10 3 0 -1 bl = 6 0 0 cl = 0 0 -3 0 0 Optimization terminated successfully. X = 1.0714 1.2857 -4.2857 0 0 FVAL = 12.8571 EXITFLAG = 1 OUTPUT = iterations: 2 algorithm: 'medium-scale: activeset' firstorderopt: [] cgiterations: [] LAMBDA = lower: [5x1 double] upper: [5x1 double] eqlin: [3x1 double] ineqlin: [0x1 double]