function [ resu, resv ] = Schnakres( n, t, xin, solin )
%Schnakres Residuals in the Schnakenberg equation
% 
if nargin < 3,
   [x,sol] = Schnakenberg(n);
else
    x = xin;
    sol = solin;
end
[y,yt] = deval( sol, t );
u=zeros(n);
vt = zeros(n);
ut = zeros(n);
v=zeros(n);
u(:) = y(1:n^2);
ut(:) = yt(1:n^2);
v(:)=y(1+n^2:end);
vt(:)=yt(1+n^2:end);
u = u';
ut=ut';
v = v';
vt=vt';
m = 4*n;
[xi,yi] = meshgrid((0:m-1)/m);
um = interpftd2( u, m, m, 0, 0 );
utm = interpftd2( ut, m, m, 0, 0 );
%figure,surf(xi,yi,um)
vm = interpftd2( v, m, m, 0, 0 );
vtm = interpftd2( vt, m, m, 0, 0 );
uxx = interpftd2( u, m, m, 2, 0 );
uyy = interpftd2( u, m, m, 0, 2 );
delu = uxx + uyy;
%figure, surf(xi,yi,delu)
vxx = interpftd2( v, m, m, 2, 0 );
vyy = interpftd2( v, m, m, 0, 2 );
delv = vxx+vyy;
usv = um.^2.*vm;
resu = utm - (delu + 1000*(0.126779 - um + usv));
resv = vtm - (10*delv + 1000*(0.792366 - usv));
figure,surf(xi,yi,resv/1000),colormap([0,0,0])
figure,surf(xi,yi,resu/1000),colormap([0,0,0])

end

