function R=rmin(p,q,xf,xd)
% Rmin - minimum reflux ratio calculation
% function R=rmin(p,q,xf,xd)
% Binary system min R=L/D
% p is the pressure in kPa
% q is the quality of the feed: 0 for sat liq., 1 for sat vap.
% xf is the feed mol frac of the 1st comp.
% xd if the mol fraction of the 1st comp. in the distillate.
if q==0
   x1=xf;
   [t,y]=bubpt2(p,xf);
else
   if q==1
      y=xf;
      [t,x1]=dewpt2(p,xf);
   else
      ts=teql(p);
      cs=[p,xf,q];
      t=ssec2(ts,'rminf(c,x)',cs);
      ks=kval(t,p);
      x1=xf/(1+(ks(1)-1)*q);
      y=ks(1)*x1;
   end
end
s=(xd-y)/(xd-x1);
R=s/(1-s);
