Figure 2.17:

Landscape for H=\frac {1}{2}p^{2}+\frac {1}{4}q^{4}-\frac {1}{2}q^{2}.

Code for Figure 2.17

Text of the GNU GPL.

main.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
% 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);