Home > matpower7.1 > mp-opt-model > lib > t > nlps_master_ex2.m

nlps_master_ex2

PURPOSE ^

SYNOPSIS ^

function nlps_master_ex2(alg)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function nlps_master_ex2(alg)
0002 if nargin < 1
0003     alg = 'DEFAULT';
0004 end
0005 problem = struct( ...
0006     'f_fcn',    @(x)f2(x), ...
0007     'gh_fcn',   @(x)gh2(x), ...
0008     'hess_fcn', @(x, lam, cost_mult)hess2(x, lam, cost_mult), ...
0009     'x0',       [1; 1; 0], ...
0010     'opt',      struct('verbose', 2, 'alg', alg) ...
0011 );
0012 [x, f, exitflag, output, lambda] = nlps_master(problem);
0013 fprintf('\nf = %g   exitflag = %d\n', f, exitflag);
0014 fprintf('\nx = \n');
0015 fprintf('   %g\n', x);
0016 fprintf('\nlambda.ineqnonlin =\n');
0017 fprintf('   %g\n', lambda.ineqnonlin);
0018 
0019 function [f, df, d2f] = f2(x)
0020 f = -x(1)*x(2) - x(2)*x(3);
0021 if nargout > 1          %% gradient is required
0022     df = -[x(2); x(1)+x(3); x(2)];
0023     if nargout > 2      %% Hessian is required
0024         d2f = -[0 1 0; 1 0 1; 0 1 0];   %% actually not used since
0025     end                                 %% 'hess_fcn' is provided
0026 end
0027 
0028 function [h, g, dh, dg] = gh2(x)
0029 h = [ 1 -1 1; 1 1 1] * x.^2 + [-2; -10];
0030 dh = 2 * [x(1) x(1); -x(2) x(2); x(3) x(3)];
0031 g = []; dg = [];
0032 
0033 function Lxx = hess2(x, lam, cost_mult)
0034 if nargin < 3, cost_mult = 1; end   %% allows to be used with 'fmincon'
0035 mu = lam.ineqnonlin;
0036 Lxx = cost_mult * [0 -1 0; -1 0 -1; 0 -1 0] + ...
0037         [2*[1 1]*mu 0 0; 0 2*[-1 1]*mu 0; 0 0 2*[1 1]*mu];

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005