function eq2 = assign(a,index,val)
%
% assign: assigns given index to new val (used in label8)
% On input:
%     a:
%     index:
%     val:
% On output
%     eq2: 
% Call:
%     eq2 = assign(a,index,val)
%

eq2 = a;
if a(index)==index 
  eq2(index) = val; 
else
  lena = length(a);
  if index>0 & index<=lena
    i1 = a(index);
    eq2(index) = val;
    while a(i1)~=i1  		
      eq2(i1) = val;
      i1 = a(i1);
    end
    eq2(i1) = val; 
  end
end

