Example: Function call: variance(matrix_50).
matrix_50:
x1 |
x2 |
x3 |
x4 |
scenario_benchmark |
scenario_probability |
1 7 2 0 |
4 5 8 3 |
8 4 1 4 |
3 6 0 9 |
2 11 6 10 |
0.2 0.2 0.3 0.3 |
at point_1:
component_name |
value |
x1 x2 x3 x4 |
1 1 1 1 |
MATLAB code (.\Aorda\PSG\MATLAB\Examples\Functions\Func_value_variance.m) for function calculation:
addpath('..')
%Define data:
H1 = [1 4 8 3;7 5 4 6;2 8 1 0;0 3 4 9];
c1 = [2;11;6;10];
p1 = [0.2;0.2;0.3;0.3];
a = [1;1;1;1];
%=======================================================================
%Calculation of function with PSG Subroutine 'functionvalue'
%Calculate variance function at point 'a':
val1 = functionvalue('variance', [], H1, c1, p1, a);
%Display function value:
disp(sprintf('functionvalue = %g', val1));
%=======================================================================
%Calculation of function with PSG Subroutine 'tbpsg_function_value'
%Create the PSG matrix 'matrix_1'(structure containing header and matrix body) and pack it to structure 'toolboxstruc_arr':
toolboxstruc_arr(1) = tbpsg_matrix_pack('matrix_1', H1, [], c1, p1);
%Create the PSG point 'point_1'(structure containing header and matrix body) and pack it to structure 'toolboxstruc_arr':
toolboxstruc_arr(2) = tbpsg_point_pack('point_1', a, []);
%Calculate variance function at point 'point_1':
val2 = tbpsg_function_value('variance(matrix_1)','point_1',toolboxstruc_arr);
%Display function value:
disp(sprintf('tbpsg_function_value = %g', val2));
%=======================================================================
%Creation of User Subroutine for calculating function value
%User subroutine is similar to the 'functionvalue'
%Create problem statement:
problem_statement = sprintf('%s\n',...
'calculate',...
'Point: point_1',...
' variance(matrix_1)',...
' ');
%Create Subroutine:
tbpsg_create_user_subroutine(problem_statement,toolboxstruc_arr,'.\','calculate_variance');
%Uncomment section to call the user subroutine 'calculate_variance':
%{
%Calculation of function with User Subroutine 'calculate_variance':
[solution_str,outargstruc_arr] = calculate_variance(H1,matrix_1_vars,c1,p1,a,point_1_vars);
%Extract function value from the solution report:
val = tbpsg_function_data(solution_str, outargstruc_arr);
%}
Program output:
functionvalue = 12.81
tbpsg_function_value = 12.81