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: fit_SEIQRDP.m
    path of file: ./repos/SEIR
    
    the code of the file until where you have to start completion: function [alpha1,beta1,gamma1,delta1,Lambda1,Kappa1,lambdaFun,kappaFun] = fit_SEIQRDP(Q,R,D,Npop,E0,I0,time,guess,varargin)
% [alpha1,beta1,gamma1,delta1,Lambda1,Kappa1,lambdaFun,varargout] =
% fit_SEIQRDP(Q,R,D,Npop,E0,I0,time,guess,varargin) estimates the
% parameters used in the SEIQRDP function, used to model the time-evolution
% of an epidemic outbreak.
%
% Input
%
%   Q: vector [1xN] of the target time-histories of the quarantined cases
%   R: vector [1xN] of the target time-histories of the recovered cases
%   D: vector [1xN] of the target time-histories of the dead cases
%   Npop: scalar: Total population of the sample
%   E0: scalar [1x1]: Initial number of exposed cases
%   I0: scalar [1x1]: Initial number of infectious cases
%   time: vector [1xN] of time (datetime)
%   guess: first vector [1x6] guess for the fit
%   optionals
%       -tolFun: tolerance  option for optimset
%       -tolX: tole
    
function [guess,kappaFun] = getKappaFun(tTarget,Q,D,guess)
        % [guess,kappaFun] = getKappaFun(tTarget,Q,D,guess) provides a first
        % estimate of the  death rate, to faciliate convergence of the main
        % algorithm.
        %
        % Input:
        %
        % tTarget: vector [1xN]: time as double
        % Q: vector [1xN] of the target time-histories of the quarantined cases
        % D: vector [1xN] of the target time-histories of the dead cases
        % guess: vector [1x9] Initial guess for kappa
        %
        % Output
        % guess: vector [1x9]  Updated intial guess
        % kappaFun: Empirical fucntion for the death rate
        
        % If less than 20 reported deceased, the death rate won't be
        % reliable. Therefore, no preliminary fitting is done.
        if max(D)<10
            kappaFun = @(a,t) a(1)./(exp(a(2)*(t-a(3))) + exp(-a(2)*(t-a(3))));
        else
            
            try
                opt=optimset('TolX',1e-6,'TolFun',1e-6,'Display','off');
                
%                myFun1 = @(a,t) a(1).*exp(-a(2)*(t+(a(3))));
               
               myFun1 = @(a,t) a(1)./(exp(a(2)*(t-a(3))) + exp(-a(2)*(t-a(3))));
               myFun2 = @(a,t) a(1).*exp(-(a(2)*(t-a(3))).^2);
               myFun3 = @(a,t) a(1) + exp(-a(2)*(t+a(3)));
                
                rate = (diff(D)./median(diff(tTarget(:))))./Q(2:end