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_DEM_eval_diff.m
    path of file: ./repos/malini/Codes/deconvolution - model/spm8
    
    the code of the file until where you have to start completion: function [D] = spm_DEM_eval_diff(x,v,qp,M,bil
    
function for evaluating projected parameters
%--------------------------------------------------------------------------
h     = 'feval(f,x,v,spm_unvec(spm_vec(p) + u*q,p))';
h     = inline(h,'f','x','v','q','u','p');
for i = 1:(nl - 1)

    % states level i
    %----------------------------------------------------------------------
    xvp = {x{i},v{i},qp.p{i},qp.u{i},M(i).pE};
    
    
    % 1st and 2nd partial derivatives (states)
    %----------------------------------------------------------------------
    if bilinear
        try
            [dgdxp dgdx] = spm_diff(h,M(i).gx,xvp{:},4,'q');
            [dgdvp dgdv] = spm_diff(h,M(i).gv,xvp{:},4,'q');
            [dfdxp dfdx] = spm_diff(h,M(i).fx,xvp{:},4,'q');
            [dfdvp dfdv] = spm_diff(h,M(i).fv,xvp{:},4,'q');
        catch
            [dgdxp dgdx] = spm_diff(h,M(i).g,xvp{:},[2 4]);
            [dgdvp dgdv] = spm_diff(h,M(i).g,xvp{:},[3 4]);
            [dfdxp dfdx] = spm_diff(h,M(i).f,xvp{:},[2 4]);
            [dfdvp dfdv] = spm_diff(h,M(i).f,xvp{:},[3 4]);
        end