None.
None.
Open in the MATLAB editor: e04wc_example
function e04wc_example fprintf('e04wc example results\n\n'); a = [1, 1, 1, 1]; bl = [1, 1, 1, 1, -1e25, -1e25, 25]; bu = [5, 5, 5, 5, 20, 40, 1e25]; istate = zeros(7, 1, 'int64'); ccon = zeros(2,1); cjac = zeros(2,4); clamda = zeros(7,1); hess = zeros(4,4); x = [1; 5; 5; 1]; [iw, rw, ifail] = e04wc; [majits, istate, ccon, cjac, clamda, objf, grad, hess, x, ... iw, rw, user, ifail] = ... e04wd(... a, bl, bu, @confun, @objfun, istate, ccon, cjac, clamda, ... hess, x, iw, rw); fprintf('Final objective value : %8.1f\n',objf); fprintf('Optimal values for x : '); fprintf(' %9.2f',x); fprintf('\nGradients at x : '); fprintf(' %9.2f',grad); fprintf('\nConstraint functions at x: '); fprintf(' %9.2f',ccon); fprintf('\nNumber of major iterations = %5d\n',majits); function [mode, ccon, cjac, user] = ... confun(mode, ncnln, n, ldcj, needc, x, cjac, nstate, user) ccon = zeros(ncnln, 1); if (nstate == 1) % first call to confun. set all jacobian elements to zero. % note that this will only work when 'derivative level = 3' % (the default; see section 11.2). cjac = zeros(ncnln, n); end if (needc(1) > 0) if (mode == 0 || mode == 2) ccon(1) = x(1)^2 + x(2)^2 + x(3)^2 + x(4)^2; end if (mode == 1 || mode == 2) cjac(1,1) = 2*x(1); cjac(1,2) = 2*x(2); cjac(1,3) = 2*x(3); cjac(1,4) = 2*x(4); end end if (needc(2) > 0) if (mode == 0 || mode == 2) ccon(2) = x(1)*x(2)*x(3)*x(4); end if (mode == 1 || mode == 2) cjac(2,1) = x(2)*x(3)*x(4); cjac(2,2) = x(1)*x(3)*x(4); cjac(2,3) = x(1)*x(2)*x(4); cjac(2,4) = x(1)*x(2)*x(3); end end function [mode, objf, grad, user] = objfun(mode, n, x, grad, nstate, user) if (mode == 0 || mode == 2) objf = x(1)*x(4)*(x(1)+x(2)+x(3)) + x(3); end if (mode == 1 || mode == 2) grad(1) = x(4)*(2*x(1)+x(2)+x(3)); grad(2) = x(1)*x(4); grad(3) = x(1)*x(4) + 1; grad(4) = x(1)*(x(1)+x(2)+x(3)); end
e04wc example results Final objective value : 17.0 Optimal values for x : 1.00 4.74 3.82 1.38 Gradients at x : 14.57 1.38 2.38 9.56 Constraint functions at x: 40.00 25.00 Number of major iterations = 6