function out=phase(dis,x)
% Phase: calculates solute distribution in a two-phase separation.
% function out=phase(dis,x)
% Argument List:
% Argument   Gives
%   dis    distribution coefficient
%    x     fraction of solute
%          going into the top phase
% phase tries various fractions of solutes sent to a phase
% 	and returns the difference between the calculated and desired
%	distribution coefficients
% See also PHASEG, PICPHASEG
% OKB, TYLC
global ns
out=[];
for k=1:length(x)
   sep([0 1,x(k)],3,[4 5]);% [No water in 4, All oil in 4, x(k) of Solute in 4]
   temp=sum(ns(4:5,:)');% total flow in each stream out of separator: row 
   xs=ns(4:5,3)./temp';% fraction solute in streams 4 and 5
   subt=xs(1)/xs(2);% ratio of the fractions of solute in 4 to 5
   if isnan(subt) % check to see if the fractions were both zero
      subt=0;
   end
   out=[out,dis-subt];% we want subt to equal dis
end
