% This computes gradient for IPM_pK.
%
% Jan 12, 2012

function [g,diagD,VtKtinvX,VDV] = gradient(X,w,MA,p,K,KtinvX,W,mu,blk)

n = size(X,1);

[V,diagD] = svd(W);
diagD = diag(diagD);
VtKtinvX = V'*KtinvX;
VDV = VtKtinvX'*diag(p*(diagD.^(-p-1)))*VtKtinvX;

g = MA'*svec(blk,VDV) - mu*1./w + mu/(1 - sum(w));
