function K=Kvalp(j,n,P)
% Kvalp		- Gives the chemical equilibrium ratio for a reaction & stream
% function K=Kvalp(j,n,P)
% For the jth reaction gives the product of the partial
% pressures of each product in the nth stream raised to its
% stoichiometric coefficient divided by the product of the reactants
% in the stream raised to the absolute powers of their 
% stoichiometric coefficients.
% Arrays ne and stoic must be set.
global ns ne stoic
K=1;
ncr=size(stoic);
if j>ncr(1)
   disp('That is not a valid reaction number')
   return
end
ns=ne(n,4:3+ncr(2));
flow=sum(ns);
if eps>flow
    disp('The flow rate in that stream is too small')
    return
end
ps=P*ns/flow;
for m=1:ncr(2)
    st=stoic(j,m);
    if st~=0
       if ps(m)<0
           disp('A flow is negative.')
           return
       end
       if ps(m)==0
          if st>0
             K=0;
             return
          else
             K=inf;
             return
          end
       end
       K=K*(ps(m)^st);
    end
end    
