hw5sol - EGM6365 Homework #5 1. Find the optimum solution...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EGM6365 Homework #5 1. Find the optimum solution of the following constrained problem Minimize 2 2 2 f = x12 + x2 + 2 x3 − x4 − 5 x1 − 5 x2 − 21x3 + 7 x4 + 100 Subject to 2 2 2 g1 = x12 + x2 + x3 + x4 + x1 − x2 + x3 − x4 − 8 ≤ 0 2 2 2 g 2 = x12 + 2 x2 + x3 + 2 x4 − x1 − x4 − 10 ≤ 0 2 2 g3 = 2 x12 + x2 + x3 + 2 x1 − x2 − x4 − 5 ≤ 0 −100 ≤ xi ≤ 100 Use Matlab “fmincon” function with various initial point including x(0) = [0, 0, 0, 0]. (a) Solve the optimization problem with the finite difference gradient calculation. (b) Solve the optimization problem with user-provided analytical gradient information. Compare the number of iteration and solution with (a). (a) Output with finite difference max Iter F-count f(x) constraint 1 5 100 -5 2 14 59.5 -0.4375 3 22 54.9971 -0.1348 4 30 54.0442 0.02619 5 37 53.7586 0.02868 6 43 53.626 0.004418 7 49 53.6345 6.201e-05 8 55 53.6347 2.825e-06 9 61 53.6347 7.877e-08 Optimization terminated successfully: Step-size 1 0.125 0.25 0.25 0.5 1 1 1 1 Directional derivative Proce -400 -16.8 -4.03 -0.597 -0.136 0.00846 0.000164 Hessia 7.96e-06 Hessia 1.94e-07 Hessia Optimization terminated successfully: Magnitude of directional derivative in search direction less than 2*options.TolFun and maximum constraint violation is less than options.TolCon Active Constraints: 9 11 x = 0.1949 0.9997 1.8303 -1.1843 fval = 53.6347 exitflag = 1 output =iterations: 9 funcCount: 31 stepsize: 1 algorithm: 'medium-scale: SQP, Quasi-Newton, line-search' lambda.ineqnonlin = 2.6877 0 0.3147 It turns out that the optimization problem converged to the same solution. The finite difference method calls the function 63 times, while the analytical gradient calls 31 times. File objfun1.m function [f,DF] = objfun1(x) f=x(1)^2+x(2)^2+2*x(3)^2-x(4)^2-5*x(1)-5*x(2)-21*x(3)+7*x(4)+100; if nargout>1 DF(1) = 2*x(1)-5; DF(2) = 2*x(2)-5; DF(3) = 4*x(3)-21; DF(4) = -2*x(4)+7; end File confun1.m function [c, ceq, DC, DCeq] = confun1(x) %Inequality constraint c(1) = x(1)^2 + x(2)^2 +x(3)^2 +x(4)^2 +x(1) - x(2) + x(3) - x(4) - 8; c(2) = x(1)^2 + 2*x(2)^2 + x(3)^2 + 2*x(4)^2 - x(1) - x(4) - 10; c(3) = 2*x(1)^2 + x(2)^2 + x(3)^2 + 2*x(1) - x(2) - x(4) - 5; %Equality constraint ceq = ; if nargout > 2 %Gradient of inequality constraints DC = [2*x(1)+1, 2*x(1)-1, 4*x(1)+2; 2*x(2)-1, 4*x(2) , 2*x(2)-1; 2*x(3)+1, 2*x(3) , 2*x(3) ; 2*x(4)-1, 4*x(4)-1, -1; %Gradient of equality constraints DCeq = ; end MATLAB commands x0 = [0, 0, 0, 0]; lb = [-100, -100, -100, -100]; ub = [100, 100, 100, 100]; option=optimset('Display','iter','GradObj','on','GradConstr','on','DerivativeCh eck','on'); [x, fval, exitflag,output,lambda] = fmincon('objfun1',x0,,,,,lb,ub,'confun1',option) lambda.ineqnonlin 2. Repeat problem 1 with the following optimization problem: Minimize f = ( x1 − 1) 2 + ( x1 − x2 ) 2 + ( x3 − 1) 2 + ( x4 − 1) 4 + ( x5 − 1)6 Subject to h1 = x4 x12 + sin( x4 − x5 ) − 2 2 = 0 42 h2 = x2 + x3 x4 − 8 − 2 = 0 −10 ≤ xi ≤ 10 This optimization problem has many local optimum points. The local optimum objective function values are 0.2415, 5.5334, 4.6026, and 9.9088. Due to the equality constraints, the problem is difficult to converge. (a) The problem did not converge with x0 = [0, 0, 0, 0, 0]. Try with x0 = [10, 0, 0, 0, 0]. Function derivative Maximum discrepancy between derivatives = 1.72305e-06 Constraint derivative Maximum discrepancy between derivatives = 8.27404e-08 x = 1.1662 1.1821 1.3803 1.5060 0.6109 fval = 0.2415 exitflag = 1 output = iterations: 47 funcCount: 114 stepsize: 1 algorithm: 'medium-scale: SQP, Quasi-Newton, line-search' (b) The problem did not converged with x0 = [0, 0, 0, 0, 0]. Try with x0 = [10, 0, 0, 0, 0]. x fval exitflag output = 1.1662 = 0.2415 = 1 = iterations: funcCount: stepsize: algorithm: 1.1821 1.3803 1.5060 0.6109 47 344 1 'medium-scale: SQP, Quasi-Newton, line-search' Matlab Command lb = [-10, -10, -10, -10, -10]; ub = [10, 10, 10, 10, 10]; option=optimset('LargeScale','off','TolFun',0.00001); %option=optimset(option,'Display','iter','GradObj','on','GradConstr','on','Deri vativeCheck','on'); %option=optimset(option,'Display','off','GradObj','on','GradConstr','on'); %option=optimset(option,'Display','iter'); x0 = [10, 0, 0, 0, 0]; [x, fval, exitflag,output,lambda] = fmincon('objfun2',x0,,,,,lb,ub,'confun2',option) fprintf(1,'\nx0=%8.4f %8.4f %8.4f %8.4f %8.4f',x0(1),x0(2),x0(3),x0(4),x0(5)); fprintf(1,'\nfval=%8.4f x=%8.4f %8.4f %8.4f %8.4f %8.4f\n',fval,x(1),x(2),x(3),x(4),x(5)); File objfun2.m function [f, DF] = objfun1(x) f = (x(1)-1)^2 + (x(1)-x(2))^2 + (x(3)-1)^2 + (x(4)-1)^4 + (x(5)-1)^6; if nargout > 1 DF(1) = 2*(x(1)-1)+2*(x(1)-x(2)); DF(2) = -2*(x(1)-x(2)); DF(3) = 2*(x(3)-1); DF(4) = 4*(x(4)-1)^3; DF(5) = 6*(x(5)-1)^5; end File confun2.m function [c, ceq, DC, DCeq] = confun1(x) %Inequality constraint c = ; %Equality constraint ceq(1) = x(4)*x(1)^2 + sin(x(4)-x(5)) -2*sqrt(2); ceq(2) = x(2) + (x(3)^4) * (x(4)^2) - 8 - sqrt(2); if nargout > 2 DC = ; DCeq = [2*x(4)*x(1) , 0 , 0 , x(1)^2+cos(x(4)-x(5)), -cos(x(4)-x(5)) , end 0 ; 1 ; 4*(x(3)^3)*(x(4)^2); 2*x(4)*x(3)^4 ; 0; ...
View Full Document

This note was uploaded on 06/07/2011 for the course EGM 6365 taught by Professor Staff during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online