%% Gradient Vector
%% 1

syms x y
f = -(sin(x) + sin(y))^2;
g = gradient(f, [x, y])

%
%% 2

[X, Y] = meshgrid(-1:.1:1,-1:.1:1);
G1 = subs(g(1), [x y], {X,Y});
G2 = subs(g(2), [x y], {X,Y});
quiver(X, Y, G1, G2)

% Copyright 2015 The MathWorks, Inc.