Example: Calculation of L2 Distance between points x = (1,1) and y = (4,5).
Function call: sqrt_quadratic(pmatrix_1).
pmatrix_1:
x1 x2 y1 y2
(1,1) 1
(2,2) 1
(1,3) -2
(3,3) 1
(2,4) -2
(4,4) 1
at point_1:
component_name |
value |
x1 x2 y1 y2 |
1 1 4 5 |
MATLAB code (.\Aorda\PSG\MATLAB\Examples\Func_value_L2_Distance.m) for function calculation:
%Define data:
H1 = [1 0 -2 0;0 1 0 -2;0 0 1 0;0 0 0 1];
a = [1;1;4;5];
%=======================================================================
%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, [], [], []);
%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 sqrt_quadratic function at point 'point_1':
val1 = tbpsg_function_value('sqrt_quadratic(matrix_1)','point_1',toolboxstruc_arr);
%Display function value:
disp(sprintf('tbpsg_function_value = %g', val1));
%=======================================================================
%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',...
' sqrt_quadratic(matrix_1)',...
' ');
%Create Subroutine:
tbpsg_create_user_subroutine(problem_statement,toolboxstruc_arr,'.\','calculate_sqrt_quadratic');
%Uncomment section to call the user subroutine 'calculate_sqrt_quadratic':
%{
%Calculation of function with User Subroutine 'calculate_sqrt_quadratic':
[solution_str,outargstruc_arr] = calculate_sqrt_quadratic(H1,matrix_1_vars,a,point_1_vars);
%Extract function value from the solution report:
val = tbpsg_function_data(solution_str, outargstruc_arr);
%}
Program output:
tbpsg_function_value = 5