% function to compute equation errors
% and Jacobian matrix
function [ferr,J] = SteamEq(x,m,V)
R = 8314. ; % Pa*m3/(kmol*K)
MW = 18.02; % kg/kmol
A = 11.21 ; % Antoine coefficients
B = 2354.7 ;
C = 280.7 ;
P = x(1) ; 
T = x(2);
% ideal gas law scaled by 100000
ferr(1) = (P*V - m/MW*R*(T+273.15))/1e5 ;
% Antoine equation
ferr(2) = log10(P) - A + B/(T+C);
% Jacobian matrix
J(1,1) = V/1.e5; J(1,2) = -m/MW*R/1.e5;
J(2,1) = 1/log(10)/P ; J(2,2) = -B/(C+T)^2;
