POLYMATH Report          REG 
 Polynomial Regression 2016-May-30 

Model: BOD = a0 + a1*Time + a2*Time^2

Variable Value 95% confidence
a0 0.224387 0.353054
a1 0.310403 0.081692
a2 -0.006439 0.003851

R^2   R^2adj   Rmsd   Variance  
0.9815572    0.9769465    0.0463377    0.0324762   

Source data points and calculated data points
  Time BOD BOD calc Delta BOD
1 1 0.6 0.528351 0.071649
2 2 0.7 0.819436 -0.119436
3 4 1.5 1.36297 0.13703
4 6 1.9 1.85499 0.04501
5 8 2.1 2.2955 -0.195495
6 10 2.6 2.68449 -0.084486
7 12 2.9 3.02196 -0.121962
8 14 3.7 3.30792 0.392077
9 16 3.5 3.54237 -0.042369
10 18 3.7 3.7253 -0.025301
11 20 3.8 3.85672 -0.056718

Problem source text
# S. 12 (b) - 2nd degree polynomial fit to BOD data
# BOD = a0 + a1*Time +a2*Time^2
# Verified Solution: a0 =0.224387, a1 = 0.310403
# a2 = -0.006439
Time =[1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
BOD=[0.6, 0.7, 1.5, 1.9, 2.1, 2.6, 2.9, 3.7, 3.5, 3.7, 3.8]
polyfit Time BOD 2

Matlab formatted problem
Create m file called PolyReg.m and paste the following text into it.
% S. 12 (b) - 2nd degree polynomial fit to BOD data
% BOD = a0 + a1*Time +a2*Time^2
% Verified Solution: a0 =0.224387, a1 = 0.310403
% a2 = -0.006439
function PolyReg
   clc;
   % Known vectors
   Time = [1; 2; 4; 6; 8; 10; 12; 14; 16; 18; 20];
   BOD = [0.6; 0.7; 1.5; 1.9; 2.1; 2.6; 2.9; 3.7; 3.5; 3.7; 3.8];
   % Derived vectors
   % Evaluate regression coefficients
   X = [Time.^0 Time.^1 Time.^2];
   [beta,bint,~,~,stats] = regress(BOD,X);
   fprintf('Regression model: BOD = a0 + a1*Time + a2*Time^2\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(' Regression Statistics ');
   disp([' Correlation Coefficient R^2 = ' num2str(stats(1))]);
   disp([' Variance = ' num2str(stats(4))]);
   % Regression plot
   plot (Time, BOD, 'bo');
   xlabel('Time');
   ylabel('BOD');
   Time_calc = linspace(min(Time), max(Time), 300)';
   BOD_calc = [Time_calc.^0 Time_calc.^1 Time_calc.^2]*beta;
   BOD_calc2 = [Time.^0 Time.^1 Time.^2]*beta;
   hold on;
   plot (Time_calc, BOD_calc, 'r-');
   hold off;
   % Residuals plot
   figure;
   plot (Time, BOD-BOD_calc2, 'ks');
   xlabel('Time');
   ylabel('BOD-BODCalc');
end

General Settings
Degree of polynomial = 2
Regression including a free parameter
Number of observations = 11