POLYMATH Report          REG 
 Polynomial Regression 2016-May-30 

Model: P = a0 + a1*TC + a2*TC^2 + a3*TC^3 + a4*TC^4

Variable Value 95% confidence
a0 24.6788 0.787233
a1 1.6062 0.054463
a2 0.036044 0.001009
a3 0.000413 4.0E-05
a4 3.96E-06 4.51E-07

R^2   R^2adj   Rmsd   Variance  
0.9999963    0.9999934    0.1410532    0.3979203   

Source data points and calculated data points
  TC P P calc Delta P
1 -36.7 1 1.04771 -0.047712
2 -19.6 5 4.51836 0.481641
3 -11.5 10 10.4154 -0.415373
4 -2.6 20 20.7392 -0.739228
5 7.6 40 39.1623 0.837664
6 15.4 60 59.6942 0.305826
7 26.1 100 100.338 -0.338419
8 42.2 200 200.265 -0.264723
9 60.6 400 399.768 0.232079
10 80.1 760 760.052 -0.051755

Problem source text
# S. 13 - Fitting Polynomials to Pressure Data
# Verified Solution: a0 =24.6788, a1 = 1.6062, a2 = 0.036044
# a3 = 0.000413, a4 = 3.96e-6
# Ref.: Comput. Appl. Eng. Educ. 6: 173, 1998
TC = [-36.7, -19.6, -11.5, -2.6, 7.6, 15.4, 26.1, 42.2, 60.6, 80.1]
P = [1, 5, 10, 20, 40, 60, 100, 200, 400, 760]
polyfit TC P 4

Matlab formatted problem
Create m file called PolyReg.m and paste the following text into it.
% S. 13 - Fitting Polynomials to Pressure Data
% Verified Solution: a0 =24.6788, a1 = 1.6062, a2 = 0.036044
% a3 = 0.000413, a4 = 3.96e-6
% Ref.: Comput. Appl. Eng. Educ. 6: 173, 1998
function PolyReg
   clc;
   % Known vectors
   TC = [-36.7; -19.6; -11.5; -2.6; 7.6; 15.4; 26.1; 42.2; 60.6; 80.1];
   P = [1; 5; 10; 20; 40; 60; 100; 200; 400; 760];
   % Derived vectors
   % Evaluate regression coefficients
   X = [TC.^0 TC.^1 TC.^2 TC.^3 TC.^4];
   [beta,bint,~,~,stats] = regress(P,X);
   fprintf('Regression model: P = a0 + a1*TC + a2*TC^2 + a3*TC^3 + a4*TC^4\n');
   disp([' a0 = ' num2str(beta(1,1),'%0.5g') ' Conf. interv.= ' num2str(bint(1,2)-beta(1,1),'%0.5g')]);
   disp([' a1 = ' num2str(beta(2,1),'%0.5g') ' Conf. interv.= ' num2str(bint(2,2)-beta(2,1),'%0.5g')]);
   disp([' a2 = ' num2str(beta(3,1),'%0.5g') ' Conf. interv.= ' num2str(bint(3,2)-beta(3,1),'%0.5g')]);
   disp([' a3 = ' num2str(beta(4,1),'%0.5g') ' Conf. interv.= ' num2str(bint(4,2)-beta(4,1),'%0.5g')]);
   disp([' a4 = ' num2str(beta(5,1),'%0.5g') ' Conf. interv.= ' num2str(bint(5,2)-beta(5,1),'%0.5g')]);
   disp(' Regression Statistics ');
   disp([' Correlation Coefficient R^2 = ' num2str(stats(1))]);
   disp([' Variance = ' num2str(stats(4))]);
   % Regression plot
   plot (TC, P, 'bo');
   xlabel('TC');
   ylabel('P');
   TC_calc = linspace(min(TC), max(TC), 300)';
   P_calc = [TC_calc.^0 TC_calc.^1 TC_calc.^2 TC_calc.^3 TC_calc.^4]*beta;
   P_calc2 = [TC.^0 TC.^1 TC.^2 TC.^3 TC.^4]*beta;
   hold on;
   plot (TC_calc, P_calc, 'r-');
   hold off;
   % Residuals plot
   figure;
   plot (TC, P-P_calc2, 'ks');
   xlabel('TC');
   ylabel('P-PCalc');
end

General Settings
Degree of polynomial = 4
Regression including a free parameter
Number of observations = 10