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: spm_fmin.m
    path of file: ./repos/bspm/thirdparty/spm8
    
    the code of the file until where you have to start completion: function [P F] = spm_fmin(fun,Q,C,varargin)
% objective function minimisation
% FORMAT [P F] = spm_fmin('fun',P,C,varargin)

    
function [P F] = spm_fmin(fun,Q,C,varargin)
% objective function minimisation
% FORMAT [P F] = spm_fmin('fun',P,C,varargin)
%
% fun - function or inline function f - fun(P,varargin)
% P   - free parameters (prior mean)
% C   - prior covariance
%
% P   - optimised parameters
% f   - optimised value of fun(P)
%
%--------------------------------------------------------------------------
% spm_fmin is a slow but robust function minimiser that uses a stochastic
% sampling of the objective function to be minimised (supplemented by a line
% search along the principal eigenvariate at the current sampling density.
% The sampling density is approximated with a Gaussian (first and second
% order moments) using that the sampling density is:
%
%           p(P) = (1/Z)*exp(-fun(P)/T)
%
% where the temperature; T is the sample standard deviation of the sampled
% objective function.
%__________________________________________________________________________
% Copyright (C) 2005 Wellcome Trust Centre for Neuroimaging

% Karl Friston
% $Id: spm_fmin.m 2031 2008-09-02 18:29:53Z karl $


% stochastic search
%--------------------------------------------------------------------------
P     = spm_vec(Q);
pmin  = P;
n     = length(P);                            % number of parameters
try
    C;                                        % prior covariance
catch
    C = speye(n,n);
end