None.
Open in the MATLAB editor: e04wb_example
function e04wb_example fprintf('e04wb example results\n\n'); x = [-1 1]; % Initialize [cwsav,lwsav,iwsav,rwsav,ifail] = e04wb('e04dg'); % Optimize [iter, objf, objgrd, x, user, lwsav, iwsav, rwsav, ifail] = ... e04dg( ... @objfun, x, lwsav, iwsav, rwsav); fprintf('Variable Value Gradient value\n'); for i=1:2 fprintf('Varbl %3d %12.8f %9.1e\n', i, x(i), objgrd(i)); end fprintf('\nFinal objective value = %15.7e\n',objf); function [mode, objf, objgrd, user] = objfun(mode, n, x, nstate, user) expx1 = exp(x(1)); objf = expx1*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1); if (mode == 2) objgrd(1) = 4*expx1*(2*x(1)+x(2)) + objf; objgrd(2) = 2*expx1*(2*x(2)+2*x(1)+1); else objgrd = zeros(2,1); end
e04wb example results Variable Value Gradient value Varbl 1 0.50000001 9.1e-07 Varbl 2 -0.99999989 8.3e-07 Final objective value = 5.3083002e-14