% copyright SYNAPTIC PROCESS SOLUTIONS INC.1996
% Routine to calculate the Niederlinski Index
% pair(i) gives the row to be paired with column i
function NI=nieder(A,pair)
[k1,k2]=size(A);
k3=0;
if length(pair)-k1==0;
	else
	disp('Error - pairing specification not correct. Check your specification')
	k3=1;
end;
y=sort(pair);
for i=1:k1-1;
	z(i)=y(i)-y(i+1)+1;
end
if any(z)|y(1)<1|y(k1)>k1
	disp('Error - pairing specification not correct. Check your specification')
	k3=1;
else
end
if k3==0;
	for i=1:k1
		B(i,:)=A(pair(i),:);
	end
	NI=prod(diag(B))/det(B);
	if NI<0;
		disp('System is unstable')
	else
	end
else
end
	
