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: grad.m
    path of file: ./repos/mtex/SO3Fun/@SO3Fun
    
    the code of the file until where you have to start completion: function g = grad(SO3F,varargin)
% gradient of an SO3Fun w.r.t. the tangent space basis 
%
% Syntax
%   G = SO3F.grad % compute the gradient

    
function g = grad(SO3F,varargin)
% gradient of an SO3Fun w.r.t. the tangent space basis 
%
% Syntax
%   G = SO3F.grad % compute the gradient
%   g = SO3F.grad(rot) % evaluate the gradient in rot
%
%   % go 5 degree in direction of the gradient
%   rot_new = exp(rot,5*degree*normalize(g)) 
%
% Input
%  SO3F - @SO3Fun
%  rot  - @rotation / @orientation
%
% Output
%  G - @SO3VectorField
%  g - @vector3d gradient of |SO3F| at rotation |rot|
%
% See also
% SO3Fun/eval orientation/exp SO3FunHarmonic/grad SO3FunRBF/grad
% SO3FunCBF/grad SO3VectorField

tS = SO3TangentSpace.extract(varargin{:});

% maybe we should return a function handle
if nargin == 1 || ~isa(varargin{1},'rotation')  
  
  if SO3F.bandwidth < getMTEXpref('maxSO3Bandwidth') && ~check_option(varargin,'check')
    SO3F = SO3FunHarmonic(SO3F);
    g = grad(SO3F,varargin{:});
  else
    g = SO3VectorFieldHandle(@(rot) SO3F.grad(rot,varargin{:}),SO3F.CS,SO3F.SS,varargin{:});
    g.tangentSpace = tS;    
  end