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: calquad.m
    path of file: ./repos/prima/benchmark/rescue_idz/matlab/interfaces/+newuoa_mat/private
    
    the code of the file until where you have to start completion: function qdiff = calquad(d, gq, hq, pq, x, xpt, debugflag)
    n = size(xpt, 1);
    npt = size(xpt, 2);
    % CALQUAD calculates
    % QDIFF = Q(X + D) - Q(X)
    % with Q being the quadratic function defined via (GQ, HQ, PQ) by

    
function qdiff = calquad(d, gq, hq, pq, x, xpt, debugflag)
    n = size(xpt, 1);
    npt = size(xpt, 2);
    % CALQUAD calculates
    % QDIFF = Q(X + D) - Q(X)
    % with Q being the quadratic function defined via (GQ, HQ, PQ) by
    % Q(Y) = <Y, GQ> + 0.5*<Y, HESSIAN*Y>,
    % where HESSIAN consists of an explicit part HQ and an implicit part PQ in Powell's way:
    % HESSIAN = HQ + sum_K=1^NPT PQ(K)*(XPT(:, K)*XPT(:, K)^T) .

    % Local variable

    if debugflag
        funname = 'CALQUAD';

        if n == 0 || npt < n + 2
            error('Error: %s: SIZE(XPT) is invalid.', funname);
        end