Lx=3;
delta=0.1;
xmin=-Lx;
xmax=Lx;
Nx=(xmax-xmin)/delta;
x=linspace(xmin,xmax,Nx);
Ly=3;
delta=0.1;
ymin=-Ly;
ymax=Ly;
Ny=(ymax-ymin)/delta;
y=linspace(ymin,ymax,Ny);
N = (Nx * Ny);
dt=0.5;
tmin=0;
tmax=4;
nt=(tmax-tmin)/dt;
tspan=linspace(tmin,tmax,nt);
e0 = zeros(N, 1);
e1 = ones(N, 1);
e2 = ones(N, 1); e2(mod(0:N-1, Nx) == 0) = 0;
e3 = zeros(N, 1); e3(mod(1:N, Nx) == 0) = 1;
ind_a = [1 Nx-1 Nx (N-Nx)];
diag_a = [e2 e3 e1 e1];
A = (1 / delta^2) * ...
spdiags([rot90(diag_a, 2) -4*e1 diag_a], [-fliplr(ind_a) 0 ind_a], N, N);
ind_b = [Nx N-Nx];
diag_b = [e1 -e1];
B = (1/(2*delta)) * ...
spdiags([-1*rot90(diag_b, 2), diag_b], [-fliplr(ind_b), ind_b], N, N);
e4 = repmat([0; ones(Nx-1, 1)], Nx, 1);
e5 = repmat([zeros(Nx-1, 1); -1], Nx, 1);
ind_c = [1, Nx-1];
diag_c = [e4, e5];
C = (1/(2*delta)) * ...
spdiags([-1*rot90(diag_c, 2), diag_c], [-fliplr(ind_c), ind_c], N, N);
A1 = full(A);
A2 = full(B);
A3 = full(C);
[X,Y] = meshgrid(x,y);
w0 = exp(-(X).^2 - ((Y.^2) / 20));
w_vec = reshape(w0, N, 1);
[Time,Omega]=ode45('vorticityBackslash',tspan,w_vec,[],A1,A2,A3);