function [t,ys]=bubpt(p,xs,erc,tbs)
% bubpt		- Determines the bubble point of a mixture
% function [t,ys]=bubpt(p,xs,erc,tbs)
% Argument List:
% Argument   Gives
%    p      pressure in kPa
%    xs     vector of liquid mol fractions.
%   tbs     bounds on temperature interval (defaults to
%             values set by upper and lower boiling pts)
%   erc     error criterion. default = 1e-4
% Returns    Giving
%    t      the bubble point temperature of the mixture.
%             in the units of Tdeg.
%    ys     vector of vapor mol fractions in equil.
%            with the liquid at that temperature.
% Ex: start301   to specify 3 compounds
%     [t,ys]=bubpt(101,[.4 .4 .2])
%     (t will contain the bubble point and ys the vapor composition)
nmax=10;
if nargin<4
   j=xs>0;
   ts=teql(p,j);
   tbs=[max(ts),min(ts)];
end
if nargin<3
   erc=1e-6;
   
end
len=length(xs)+2;
cs=[p,len,xs];
c=cs;
cv='1-sum(c(3:c(2)).*kval(x,c(1)))';
x=tbs(1);
suml=eval(cv);
x=tbs(2);
sumr=eval(cv);
if sumr*suml>0
   disp('Same signs on the end points')
   return
end
t=ssec2(tbs,cv,c,erc,nmax); 
% t=fzero(cv,tbs,erc,[],P1);
ys=xs.*kval(t,p);

