POLYMATH Report          REG 
 Nonlinear Regression (L-M) 2016-May-31 
Model: r = ks*KCH4*(PCH4*PH2O^2-PCO2*PH2^4/5.051e-5)/(1+KCH4*PCH4)

Variable Initial guess Value 95% confidence
ks 1 0.002784 3.84E-06
KCH4 1 101.999 0.884321

R^2   R^2adj   Rmsd   Variance  
0.9968612    0.9965125    9.331E-07    1.171E-11   

Source data points and calculated data points
  PCH4 PH2O PCO2 PH2 r r calc Delta r
1 0.06298 0.23818 0.0042 0.01669 0.000137 0.000136 7.52E-07
2 0.03748 0.26315 0.00467 0.01686 0.000156 0.000152 3.46E-06
3 0.05178 0.29557 0.00542 0.02079 0.0002 0.000204 -3.31E-06
4 0.04978 0.23239 0.00177 0.07865 5.7E-05 6.3E-05 -5.96E-06
5 0.04809 0.29491 0.00655 0.02464 0.000202 0.000199 2.67E-06
6 0.03849 0.24171 0.00184 0.06873 7.89E-05 8.28E-05 -3.9E-06
7 0.03886 0.26048 0.00381 0.0148 0.00015 0.000151 -8.06E-07
8 0.0523 0.26286 0.05719 0.01635 0.00016 0.000158 1.51E-06
9 0.05185 0.33529 0.00718 0.0282 0.000262 0.000259 2.79E-06
10 0.06432 0.24787 0.00509 0.02055 0.000144 0.000148 -3.49E-06
11 0.09609 0.28457 0.00652 0.02627 0.000202 0.000203 -1.01E-06

Problem source text
# S. 30* - Nonlinear Regression
# Catalytic Reforming Reac.
# Verified Final Values: ks = 0.002784, KCH4 = 101.999
# Ref.:Prob. 3.10 in Problem Solving in Chemical...
PCH4 = [0.06298, 0.03748, 0.05178, 0.04978, 0.04809, 0.03849, 0.03886, 0.0523, 0.05185, 0.06432, 0.09609]
PH2O = [0.23818, 0.26315, 0.29557, 0.23239, 0.29491, 0.24171, 0.26048, 0.26286, 0.33529, 0.24787, 0.28457]
PCO2 = [0.0042, 0.00467, 0.00542, 0.00177, 0.00655, 0.00184, 0.00381, 0.05719, 0.00718, 0.00509, 0.00652]
PH2 = [0.01669, 0.01686, 0.02079, 0.07865, 0.02464, 0.06873, 0.0148, 0.01635, 0.0282, 0.02055, 0.02627]
r = [0.00013717, 0.00015584, 0.00020028, 5.7E-05, 0.0002015, 7.887E-05, 0.00014983, 0.00015988, 0.00026194, 0.00014426, 0.00020195]
nlinfit r = ks*KCH4*(PCH4*PH2O^2-PCO2*PH2^4/5.051e-5)/(1+KCH4*PCH4)
m(ks)=1
m(KCH4)=1

Matlab formatted problem
Create m file called PolyNlR.m and paste the following text into it.
% S. 30* - Nonlinear Regression
% Catalytic Reforming Reac.
% Verified Final Values: ks = 0.002784, KCH4 = 101.999
% Ref.:Prob. 3.10 in Problem Solving in Chemical...
function PolyNLR
   clc;
   % Known vectors
   PCH4 = [0.06298; 0.03748; 0.05178; 0.04978; 0.04809; 0.03849; 0.03886; 0.0523; 0.05185; 0.06432; 0.09609];
   PH2O = [0.23818; 0.26315; 0.29557; 0.23239; 0.29491; 0.24171; 0.26048; 0.26286; 0.33529; 0.24787; 0.28457];
   PCO2 = [0.0042; 0.00467; 0.00542; 0.00177; 0.00655; 0.00184; 0.00381; 0.05719; 0.00718; 0.00509; 0.00652];
   PH2 = [0.01669; 0.01686; 0.02079; 0.07865; 0.02464; 0.06873; 0.0148; 0.01635; 0.0282; 0.02055; 0.02627];
   r = [0.00013717; 0.00015584; 0.00020028; 5.7E-05; 0.0002015; 7.887E-05; 0.00014983; 0.00015988; 0.00026194; 0.00014426; 0.00020195];
   % Derived vectors
   % Evaluate regression coefficients
   X = [PCH4 PH2O PCO2 PH2];
   n = 11;
   Beta0 = [1 1]; % initial guess vector
   [BetaOpt,resid,J,sigma,mse] = nlinfit(X, r, @NLRfun, Beta0);
   ci = nlparci(BetaOpt,resid,'jacobian',J);
   r_Calc = NLRfun(BetaOpt, X);
   fprintf('\nNonlinear Regression model parameters solution\n');
   fprintf('\nRegression model: r=ks*KCH4*(PCH4*PH2O^2-PCO2*PH2^4/5.051e-5)/(1+KCH4*PCH4)\n');
   disp([' ks = ' num2str(BetaOpt(1),'%0.5g') ' Conf. interv. = ' num2str(ci(1,2)-BetaOpt(1),'%0.5g')]);
   disp([' KCH4 = ' num2str(BetaOpt(2),'%0.5g') ' Conf. interv. = ' num2str(ci(2,2)-BetaOpt(2),'%0.5g')]);
   disp(' Regression Statistics ');
   disp([' Variance = ' num2str(mse)]);
   % Regression plot
   plot (r, r_Calc, 'bo');
   xlabel('r');
   ylabel('r_Calc');
   hold on;
   plot (r, r, 'r-');
   hold off;
   % Residuals plot
   figure;
   plot (r, r-r_Calc, 'ks');
   xlabel('r');
   ylabel('r-rCalc');
end

function r = NLRfun(beta, X)
   ks = beta(1);
   KCH4 = beta(2);
   PCH4 = X(:,1);
   PH2O = X(:,2);
   PCO2 = X(:,3);
   PH2 = X(:,4);
   r=ks.*KCH4.*(PCH4.*PH2O.^2-PCO2.*PH2.^4./5.051e-5)./(1+KCH4.*PCH4);
end

General Settings
Sample size 11
Model vars 2
Indep vars 4
Iterations 71
Max iterations 100