Example: calculation of gradient of avg function.

 

matrix_1:

 

x1

x2

x4

scenario_benchmark

2

-3

1

-1

6

2

1

-7

1.5

15

-1

-1

 

point_1:

 

component_name

value

x1

x2

x4

1

1

1

 

MATLAB code (.\Aorda\PSG\MATLAB\Examples\Functions\Func_value_gradient.m) for function calculation:

 

%Calculation of gradient using 'functionsensitivity':

%Define data:

H1 = [2 -1 1;-3 6 -7;1 2 1.5];

c1 = [15;-1;-1];

a = [1;1;1];

%Calculate gradient at point 'a':

point_1 = functionsensitivity('avg', [], H1, c1, [], a);

%Display result:

disp('Gradient of average function at point ''a'' using ''functionsensitivity'' = ');

disp(point_1)

%=======================================================================

%Calculation of gradient using 'mpsg_function_sensitivity':

%Create the PSG matrix 'matrix_1'(structure containing header and matrix body) and pack it to structure 'iargstruc_arr':

iargstruc_arr(1) = matrix_pack('matrix_1', H1, [],  c1, []);

%Create the PSG point 'point_a'(structure containing header and matrix body) and pack it to structure 'iargstruc_arr':

iargstruc_arr(2) = point_pack('point_a', a, []);

%Calculate gradient at point 'point_a':

point_2 = mpsg_function_sensitivity('avg(matrix_1)','point_a',iargstruc_arr);

%Display result:

disp('Gradient of average function at point ''point_a'' using ''mpsg_function_sensitivity'' = ');

disp(point_2.values')

 

 

Program output:

 

Gradient of average function at point 'a' using 'functionsensitivity' =

   0.0000

  -2.3333

   1.5000

 

Gradient of average function at point 'point_a' using 'mpsg_function_sensitivity' =

   0.0000

  -2.3333

   1.5000