clear;clc;
          time = [0	2	4	6	8	10	12	14	16	18	20	22	24];
          temp = [8.43	7.97	7.66	7.51	7.97	10.43	13.36	15.39	15.71	14.61	12.28	10.59	9.82];

          % Get coefficients of the 5th degree polynomial
          d = 7; % the degree of the approximating curve
          c = polyfit( time, temp, d );
          xx = 0:0.1:24;
          yy = polyval(c,xx);

          % 10 and 20 are approximate times when time will be 12 degrees
          t(1) = fzero( @(x)polyval(c,x)-12 , 10 );
          t(2) = fzero( @(x)polyval(c,x)-12 , 20 );
          y = polyval(c, t);
          disp(['Temp equals 12 degrees at time = ' num2str(t(1)) ' and time = ' num2str(t(2))]);

          % Plot it all
          hold on
          plot( xx, yy, 'r' );             % plot the approximation
          plot( [0 24], [12 12], 'k-.' );  % plot the line temp=12
          plot( time, temp, 'b*' );        % plot the data
          plot( t, y, 'go' )               % plot where curve intersect temp=12
          hold off