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: getCostGrad.m
    path of file: ./repos/lrslibrary/libs/manopt/manopt/privatetools
    
    the code of the file until where you have to start completion: function [cost, grad, storedb] = getCostGrad(problem, x, storedb)
% Computes the cost function and the gradient at x in one call if possible.
%
% function [cost, storedb] = getCostGrad(problem, x, storedb)
%
% Returns the value at x of the cost function described in the problem
% structure, as well as the gradient at x. The cache database storedb is
% passed along, possibly modified and returned in the pr
    
function wants to deal with the store
        % structure or not.
        switch narg
            case 1
                [cost, grad] = problem.costgrad(x);
            case 2
                % Obtain, pass along, and save the store structure
                % associated to this point.
                store = getStore(problem, x, storedb);
                [cost, grad, store] = problem.costgrad(x, store);
                storedb = setStore(problem, x, storedb, store);
            otherwise
                up = MException('manopt:getCostGrad:badcostgrad', ...
                    'costgrad should accept 1 or 2 inputs.');
                throw(up);
        end