function res = potqp(x,n,a1,a2,l)

s = 0;

for k1 = 1:n
    for k2 = 1:n
        for k3 = 1:n
        s = s + l*exp(-k1-k2-k3)*cos(2*pi*(k1+a1*k2+a2*k3)*x);
        end
    end
end

res = s;

end
