
% matlab file syntesgass.m
% Dette er modellen for prøveeksamen i Appendix
% kall:
% x0=[25,7]
% x = fmins('syntesegass',x0)
%  xch4, xh2o, xco, xh2, xco2 

function y=f(x)
n0ch4=0.3*100;
n0h2o=0.7*100;
p=1;
K1=1000;
K2=1;
x1=x(1);
x2=x(2);

nch4=n0ch4-x1
nh2o=n0h2o-x1-x2
nco=x1-x2
nh2=3*x1+x2
nco2=x2
ntot=nch4+nh2o+nco+nh2+nco2

xch4=nch4/ntot;
xh2o=nh2o/ntot;
xco =nco /ntot;
xh2 =nh2 /ntot;
xco2=nco2/ntot;

diff1 = K1/(p^2) - xco*(xh2)^3 / (xch4*xh2o);
diff2 = K2 - xco2*xh2/(xco*xh2o);

y = diff1^2 + diff2^2


