function [Jb,i,j] = Jbar(n);

% wolkowicz & sotirov
% 9.05.2001 waterloo
% call: [Jb,i,j] = Jbar(n);


if n<3
disp('MUST BE: n =>3');
Jb = [];
IJ = [];
break;
end;

Jb = zeros(n*n+1);        % off diagonal elements for the diagonal blocks
r = 1:n;                  % must: q<>r
for p = 1:n
for q = 1:n
I = setdiff(r,q);
r = 1:n;
Jb((p-1)*n + q +1, (p-1)*n + I +1) = 1;
end;
end;

r = 1:n-1;                % diagonal elements of the off-diagonal blocks
for p = 1:n-1             % must: p<>r; p,r <> n
for q = 1:n
I = setdiff(r,p);
r = 1:n-1;
Jb((p-1)*n + q +1, (I-1)*n + q + 1) = 1;
end;
end;

rr=1:n;

%for k=1:n
%Jb((n-3)*n+1+k, (n-2)*n+1+rr)=0;  % (r,p), (p,r) <> (n-2,n-1), (n-1,n-2)
%Jb((n-2)*n+1+rr, (n-3)*n+1+k)=0;
%end;

% faster versin of previous
Jb((n-3)*n+1+rr, (n-2)*n+1+rr)=0;    % (r,p), (p,r) <> (n-2,n-1), (n-1,n-2)
Jb((n-2)*n+1+rr, (n-3)*n+1+rr)=0;

joj = tril(Jb ,-1);
[i,j] = find(joj);                   % find on which postions should be zeros
IJ = [i,j];





