You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: getStepSizeFD.m
    path of file: ./repos/PESTO/private
    
    the code of the file until where you have to start completion: function fdStepSize = getStepSizeFD(theta, objectiveFunction, mode)

% This function computes the optimal step size for finite differences.

    
function fdStepSize = getStepSizeFD(theta, objectiveFunction, mode)

% This function computes the optimal step size for finite differences.
%
% Parameters:
%   theta: parameter vector
%   objectiveFunction: the original objective function
%   mode: double, specifying if the output of the original objective func.
%           1: only objective value is passed
%           2: gradients are computed
%
% Return values:
%   fdStepSize: vector of step sizes

    % Initialization
    nPar = length(theta);
    fdStepSize = zeros(nPar, 1);

    switch mode
        case 1
        % The original objective funcion can only compute the objective,
        % step sizes for the gradient are needed
        
            for j = 1 : nPar
                delta = zeros(nPar,1);
                gradients = zeros(1,7);
                qualityVector = zeros(1,7);

                % Compute gradient for different step sizes
                for k = 3 : 9
                    delta(j) = 10^(-k);
                    Jplus = objectiveFunction(theta + delta);
                    Jminus = objectiveFunction(theta - delta);
                    gradients(k-2) = 0.5 * 10^k * (Jplus - Jminus);
                end