% computes the gradient of F using the differential approximation to |x|
function g=gradF(A,At,b,p,lambda,sigma,x)

    m = size(A,1); n = size(A,2);
    erf_vec = zeros(n,1);
    alpha = sqrt(2/pi)*(sigma);
	grad_vec1 = 2*At*(A*x - b);
	grad_vec2 = zeros(n,1);

    for j=1:n
        xj = x(j);
		phi_sig_xj = xj*erf(xj/(sqrt(2)*sigma)) + alpha*exp(-xj^2/(2*sigma^2));
        grad_vec2(j) = (phi_sig_xj)^(p-1) * erf(xj/(sqrt(2)*sigma)); 
    end
    g = grad_vec1 + lambda*p*grad_vec2;

end
