function z=f(x)
% Called with: z = fzero('nh3eq',0.1)
%          or: z = fmins('nh3eq',0.1)

p=300;
nn2=1-x;
nh2=3-3*x;
nnh3=2*x;
ntot=nn2+nh2+nnh3;
xn2=nn2/ntot
xh2=nh2/ntot
xnh3=nnh3/ntot
pn2=p*xn2;
ph2=p*xh2;
pnh3=p*xnh3;
Q = (pnh3^2 / (pn2 * ph2^3));
K=6.36*0.00001;    % T= 700 K
z=Q-K;



