% Example MATLAB script for testing Python module with function handles

% Inputs
A = [1.0, 2.5, 3.7];
B = [4.1, 5.2, 6.3];
singleArray = single([1.1, 2.2, 3.3]);
complexNum = 2 + 3i;
int8Var = int8(100);
uint8Var = uint8(200);
int16Var = int16(-3000);
uint16Var = uint16(40000);
int32Var = int32(-200000);
uint32Var = uint32(400000);
int64Var = int64(-5000000000);
uint64Var = uint64(10000000000);
nanVar = NaN;
infVar = Inf;
logicalVar = true;
charArray = 'Hello, MATLAB!';
structVar = struct('field1', 1, 'field2', 'text', 'field3', [1, 2, 3]);
cellArray = {'text', 123, true};
mapObj = containers.Map({'key1', 'key2'}, {'value1', 'value2'});
categories = {'small', 'medium', 'large'};
categoricalVar = categorical({'medium', 'large', 'small', 'medium'}, categories);
sparseArray = sparse([1, 2, 3], [4, 5, 6], [7, 8, 9]);
stringArray = ["first", "second", "third"];
x = 0:0.1:10;

% Creating istari_input dictionary
istari_input = dictionary();
istari_input('A') = @() A;
istari_input('B') = @() B;
istari_input('singleArray') = @() singleArray;
istari_input('complexNum') = @() complexNum;
istari_input('int8Var') = @() int8Var;
istari_input('uint8Var') = @() uint8Var;
istari_input('int16Var') = @() int16Var;
istari_input('uint16Var') = @() uint16Var;
istari_input('int32Var') = @() int32Var;
istari_input('uint32Var') = @() uint32Var;
istari_input('int64Var') = @() int64Var;
istari_input('uint64Var') = @() uint64Var;
istari_input('nanVar') = @() nanVar;
istari_input('infVar') = @() infVar;
istari_input('logicalVar') = @() logicalVar;
istari_input('charArray') = @() charArray;
istari_input('structVar') = @() structVar;
istari_input('cellArray') = @() cellArray;
istari_input('mapObj') = @() mapObj;
istari_input('categoricalVar') = @() categoricalVar;
istari_input('sparseArray') = @() sparseArray;
istari_input('stringArray') = @() stringArray;
istari_input('x') = @() x;

% The number of this line (55) should be passed as an argument to the `extract` function

% Outputs
C = A + B;
y = sin(x);
y2 = cos(x);

% Creating istari_output dictionary
istari_output = dictionary;
istari_output('C') = @() C;
istari_output('y') = @() y;
istari_output('y2') = @() y2;

% Plotting a graph
x = 0:0.1:10;
y = sin(x);
figure;
plot(x, y);
title('Sine Wave');
xlabel('x');
ylabel('sin(x)');

% Another plot with different data type
y2 = cos(x);
figure;
plot(x, y2);
title('Cosine Wave');
xlabel('x');
ylabel('cos(x)');

% Calling the new functions
arraySum = calculateSum(A);
arrayProduct = calculateProduct(B);
arrayMean = calculateMean(singleArray);

% Displaying the results
fprintf('Sum of A: %.2f\n', arraySum);
fprintf('Product of B: %.2f\n', arrayProduct);
fprintf('Mean of singleArray: %.2f\n', arrayMean);

% New functions for calculations

% Function to calculate the sum of all elements in an array
function sumValue = calculateSum(array)
    % calculateSum(array) returns the sum of all elements in the input array.
    % Input:
    %   array - A numeric array whose elements will be summed up
    % Output:
    %   sumValue - The sum of all elements in the array
    sumValue = sum(array);
end

% Function to calculate the product of all elements in an array
function productValue = calculateProduct(array)
    % calculateProduct(array) returns the product of all elements in the input array.
    % Input:
    %   array - A numeric array whose elements will be multiplied together
    % Output:
    %   productValue - The product of all elements in the array
    productValue = prod(array);
end

% Function to calculate the mean of an array
function meanValue = calculateMean(array)
    % calculateMean(array) returns the mean value of all elements in the input array.
    % Input:
    %   array - A numeric array whose mean value will be calculated
    % Output:
    %   meanValue - The mean value of the elements in the array
    meanValue = mean(array);
end
