function P3_14 clear, clc, format short g, format compact prob_title = (['Antoine Parameters by Linear Regression']); ind_var_name=[' T (C) ']; dep_var_name=['TlogPv ']; xyData=[-60.72272 -70. 0.8674675 -59.25998 -60. 0.9876663 -55.01853 -50. 1.100371 -48.3806 -40. 1.209515 -39.22488 -30. 1.307496 -28.06241 -20. 1.403121 -14.9693 -10. 1.49693 0 0 1.582063 16.62758 10. 1.662758 34.88586 20. 1.744293 54.64541 30. 1.821514 75.68378 40. 1.892095 98.14213 50. 1.962843 121.7874 60. 2.029789 146.5395 70. 2.093422 172.3783 80. 2.154728 199.3359 90. 2.214844 227.1842 100. 2.271842 256.1218 110. 2.32838 285.6253 120. 2.380211]; X=xyData(:,2:end); y=xyData(:,1); [m,n]=size(X); freeparm=input(' Input 1 if there is a free parameter, 0 otherwise > '); [Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm); disp([' Results, ' prob_title]); Res=[]; if freeparm==0, nparm = n-1; else nparm = n; end for i=0:nparm if freeparm, ii=i+1; else ii=i; end Res=[Res; ii Beta(i+1) ConfInt(i+1)]; end disp(' Parameter No. Beta Conf_int'); disp(Res); disp([' Variance ', num2str(Var)]); disp([' Correlation Coefficient ', num2str(R2)]); plot(y,y-ycal,'*') title(['Residual Plot, ' prob_title]) % residual plot xlabel([dep_var_name '(Measured)']) ylabel('Residual') pause plot(X(:,1),ycal, 'r-',X(:,1),y,'b+' ) title(['Calculated/Experimental Data ' prob_title]) xlabel([ind_var_name]) ylabel([dep_var_name]) function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm) [m,n]=size(X); % m-number of rows, n-number of columns if freeparm X=[ones(m,1) X]; % Add column of ones if there is a free parameter npar=n+1; else npar=n; end A=X'*X Xty=X'*y Beta=X\y; % Solve X'Beta = Y using QR decomposition ycalc=X*Beta; % Calculated dependent variable values Var=((y-ycalc)'*(y-ycalc))/(m-npar); % variance ymean=mean(y); R2=(ycalc-ymean)'*(ycalc-ymean)/((y-ymean)'*(y-ymean));%linear correlation coefficient % Calculate the confidence intervals A=X'*X; Ainv=A\eye(size(A)); %Calculate the inverse of the X'X matrix tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306 2.2622 2.2281... 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199 2.1098 2.1009 2.093 2.086 2.0796... 2.0739 2.0687 2.0639 2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369... 2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211 2.0195 2.0181 2.0167... 2.0154 2.0141]; % 95 percent probability t-distr. values if (m-npar)>45 t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45 else t=tdistr95(m-npar); end for i=1:npar ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals end