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

nleqs_master_ex2

PURPOSE ^

SYNOPSIS ^

function nleqs_master_ex2(alg)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function nleqs_master_ex2(alg)
0002 if nargin < 1
0003     alg = 'DEFAULT';
0004 end
0005 x0 = [1; 2];
0006 opt = struct( ...
0007     'verbose', 2, ...
0008     'alg', alg, ...
0009     'fd_opt', struct( ...
0010         'jac_approx_fcn', @jac_approx_fcn2, ...
0011         'labels', {{'P','Q'}}), ...
0012     'gs_opt', struct('x_update_fcn', @x_update_fcn2) );
0013 [x, f, exitflag, output] = nleqs_master(@f2, x0, opt);
0014 fprintf('\nexitflag = %d\n', exitflag);
0015 fprintf('\nx = \n');
0016 fprintf('   %2g\n', x);
0017 fprintf('\nf = \n');
0018 fprintf('   %12g\n', f);
0019 
0020 function [f, J] = f2(x)
0021 %% from Christi Patton Luks, https://www.youtube.com/watch?v=pJG4yhtgerg
0022 f = [  x(1)^2 +   x(1)*x(2)   - 10;
0023        x(2)   + 3*x(1)*x(2)^2 - 57  ];
0024 if nargout > 1
0025     J = [   2*x(1)+x(2)    x(1);
0026             3*x(2)^2       6*x(1)*x(2)+1    ];
0027 end
0028 
0029 function JJ = jac_approx_fcn2()
0030 %% for use with fast-decoupled Newton's method
0031 J = [7 2; 27 37];
0032 JJ = {J(1,1), J(2,2)};
0033 
0034 function x = x_update_fcn2(x, f)
0035 %% for use with Gauss-Seidel method
0036 x(1) = sqrt(10 - x(1)*x(2));
0037 x(2) = sqrt((57-x(2))/3/x(1));

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