function plotmat(M)

% check dimensions
if size(M,1)~=2 || size(M,2)~=2,
    error('Matrix must be 2-by-2');
end

% make grid, reshape into column vectors
[x, y] = meshgrid(-1:.1:1, -1:.1:1);
vx = x(:);
vy = y(:);

% multiply by M, separate x and y components
p = M*[vx'; vy'];
px = p(1,:)';
py = p(2,:)';

% compute quadratic form z
z = x.*reshape(px,[21 21]) + y.*reshape(py,[21 21]);

% plot as vector field
figure(1);
clf;
subplot(1,2,1);
quiver(vx,vy,px,py);
axis image;
xlabel('x_1');
ylabel('x_2');

% plot as surface with contours
subplot(1,2,2);
mesh(x,y,z);
hold on;
contour3(x,y,z,'k');
xlabel('x_1');
ylabel('x_2');

