% quadform.m 
% illustration of quadratic forms
clear

% Generate the data
x1=-1:.02:1;
x2=x1;
x=[x1' x2'];
A=[1 0 ; 0 1];
N=length(x1);
for n1=1:N
   for n2=1:N
	data(n1,n2)=[x1(n1) x2(n2)]*A*[x1(n1) x2(n2)]';
   end
end

% plot it
mesh(x1,x2,data)

% use in the above various matrices.
% [1 0 ; 0 1] is pos def
% [1 0 ; 0 0] is pos semidef
% [1 0 ; 0 -1] is indef
% [-1 0 ; 0 0 ] is neg semidef
% [-1 0 ; 0 -1] is neg def
% Compare the behaviour of the graphs with the eigenvalues of the matrix A.
% use the matlab command eig(A)