%Given an interval matrix [n,N], this program tells whether its %mrk is 0 1 or greater than 1 %It uses %-the program reduce.m to eliminate the rows and the columns such that all its entries contain 0 %-the program rk1nnr.m, which says whether an interval matrix with nonnnegative entries contains a rk 1 matrix function a=rk01(n,N) % we reduce the interval matrix [n,N]; the interval matrix we obtain % is given by the first half of the columns of X and the second half % of the columns of X X=reduce(n,N) ; [p,r]=size(X); if [p,r]==[0,0] %in this case obiously mrk is 0 a=0; return end q=r/2; m=X(:,1:q); M=X(:,q+1:r); % we construct a matrix v with 2 rows such that its columns are the % indices of the entries of [m,M] such that either % min negative max positive or % min zero max positive or % min negative max zero v=zeros(2,0); for i=1:p for j=1:q if m(i,j)<=0 & M(i,j)>=0 & -m(i,j)+M(i,j)>0 v=[v [i; j]]; end end end % now we construct two tridimensional matrices A and B such that % for every i the slice [A(:,:,i) B(:,:,i)] is an interval matrix % whose entries are all either contained in the set of the % nonnegative real numbers or in the set of nonpositive real numbers % and the union of [A(r,s,i),B(r,s,i)] with i varying is the entry % r,s of [m,M] A=zeros(p,q,1); A(:,:,1) =m; B=zeros(p,q,1); B(:,:,1) =M; for i=1:size(v,2) A=cat(3,A,A); B=cat(3,B,B); for l=1:size(A,3)/2 B(v(1,i),v(2,i),l)=0; A(v(1,i),v(2,i),l+size(A,3)/2)=0; end end % Now we consider every slice of A,B and, by multyplying some of its rows and % some of its columns by -1, we change it in such way that all the entries % of the first row and of the first column of the slice are contained % in the set of nonnegative real numbers. for k=1:size(A,3) for i=1:size(A,1) if A(i,1,k)<0 X=A(i,:,k); Y=B(i,:,k); A(i,:,k)=min(-X,-Y); B(i,:,k)=max(-X,-Y); end end for j=2:size(A,2) if A(1,j,k)<0 U=A(:,j,k); V=B(:,j,k); A(:,j,k)=min(-U,-V); B(:,j,k)=max(-U,-V); end end end % b is the set of the indices i of the slices of A B such that at least some entry % of [A(:,:,i) , B(:,:, i)] intersect the set of the negative real numbers % b=zeros(1,0); for i=1:size(A,3) if sum(sum(A(:,:,i)<0))>0 b=[b,i]; end end % I define again A and B by excluding the slices whose indices are in b x=size(A,3); A=A(:,:,setdiff(1:x,b)); B=B(:,:,setdiff(1:x,b)); for i=1:size(A,3) if rk1nnr(A(:,:,i),B(:,:,i))==1 a=1; return end end a="mrk at least 2";