Linear Regression Fitting of A Nonlinear Expression (Example 1)
Linear Regression Fitting of A Nonlinear Expression (Example 1)
dCA
kC A
n
dt
Rearranging the expression and then integrating from
an initial concentration of CA0 to a final concentration CA
gives:
CA
dCA t
CA0 CA
kdt
0
CA
ln kt or C A C A 0e kt
C A0
Based on the data below find the rate constant k for the first order reaction:
a1=(n*sum(x.*y)-sum(x)*sum(y))/(n*sum(x.^2)-sum(x)^2);
a0=sum(y)/n-a1*sum(x)/n;
Sb=sum((y-sum(y)/n).^2);
r=sqrt((Sb-S)/Sb);
fprintf('\nThe correlation coefficient of the regression line equals %.6f\n\n',r);
We could also solve example using polyfit
coeff=polyfit(x, y, 1);
fprintf('\nThe slope of the regression line equals %.6f\n',coeff(1));
fprintf('\nThe intercept of the regression line equals %.6f\n',coeff(2));
fprintf('\nThus k equals %.7f\n',-coeff(1));