function grad = powellgrad(x)
% usage:  hess = powellgrad(x)
% description: Returns the gradient vector for
% powell(x).

% a little bit of bulletproofing
if (~isvector(x) | (length(x) ~= 4))
  error('powell: needs a two-dimensional vector argument');
end
if (size(x,2) ~= 1)
  error('powell: needs a column vector');
end 
% the actual calculation
grad = [2*x(1)+20*x(2)+40*(10*x(1)-x(4))^3;
        20*x(1)+200*x(2)+4*(x(2)-2*x(3))^3;
        10*x(3)-10*x(4)-8*(x(2)-2*x(3))^3;
        -10*x(3)+10*x(4)-4*(10*x(1)-x(4))^3];
