
%  The script file table2.m computes and plots the real spectrum
%  of the PT-symmetric potential p(x) = x^4 + iax.   It is listed
%  in Table 2 and reproduces Figure 2 of the paper:
%  JAC Weideman, "Spectral Differentiation Matrices for the Numerical
%  Solution of Schroedinger's equation" (submitted).

warning off;   
N =  32; c = 1.8;            % Construct second derivative
[x, DM] = herdif(N, 2, c);   % Hermite matrix of size NxN and
D2 = DM(:,:,2);              % scaling parameter c.

for a = linspace(0,22,1000);     % Start loop over a.

    A  = -D2+diag(x.^4+i*a*x);   % Assemble A and compute
    E  = sort(eig(A));           % and sort its eigenvalues.
    E  = E(1:10);                % Retain only ten.

  ell = find(abs(imag(E)) < sqrt(eps));  % Retain only e-values
    E = E(ell);                          % that are real (approx).

   plot(a*ones(size(E)),E,'.','MarkerSize',12); hold on;   % Plot them.

end

xlabel('a','FontSize',16)
ylabel('E','FontSize',16)

