% contour plot of V(x,y)=1/2 y^2 + 1/4 x^4 - 1/2 x^2
% save as epslatex and
% avoid using gnuplot for this figure()
%
% jbr, 9/3/2011
%
n = 101;
x = linspace(-1.5, 1.5, n);
y = linspace(-1.0, 1.0, n);
xx = kron(x, ones(n,1));
yy = kron(y', ones(1,n));
xx2 = xx.*xx;
xx4 = xx2.*xx2;
yy2 = yy.*yy;
z = 0.5*(yy2) + 0.25*xx4 -0.5*xx2;
val = [-0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4];
[c, lev] = contour(x,y,z,val);
axis([-1.5, 1.5, -1, 1])
xlabel ("$q$");
% avoid rotating y-axis label
text (-1.7, 0, "$p$")
%print ("homoclinic.tex", "-depslatex");
% write contour data for gnuplot
col = 1;
myfile = fopen('homoclinic.dat', 'w');
while col <= size(c, 2)
coln = col + c(2,col);
data = c(:,col+1:coln);
% print this contour data and move to next contour line
fprintf(myfile, '%e %e \n', data)
fprintf(myfile, '\n\n')
col = coln + 1;
end
fclose(myfile);