% Number of spatial grid points 
N=4;

% Changed to the interval [0, 2 pi] from the notes 
h = 2*pi/N;
e = ones(N,1);
A = spdiags([-e/h^2 (2/h^2+1)*e -e/h^2], -1:1, N, N);

% periodic entries
A(1,N) = -1/h^2;
A(N,1) = -1/h^2;

% Inverse
G = inv(full(A));

% First row/column 
g = G(1,:);

% Check analytic expression 
r = 1 +h^2/2 + h*sqrt(1+h^2/4);
A = h^2*(r^N-1)/(-2*(r+r^(N-1))+(2+h^2)*(1+r^N));
j=0:(N-1);
g2 = A/(r^N -1)*(r.^j + r.^(N-j));

