%
%   PIN_FIN_1.M   Function Evaluation, Plotting, and Use of Function Files
%                     Heat Transfer Analysis of a Temperature Probe
%
%   This example evaluates and plots the measurement error associated with a
%   pin-shaped temperature probe that is inserted through a wall into a fluid.
%   Given a set of design parameters (Tinfo, ho, Tinfi, hi, k, etc.), a function
%   subprogram, PIN_FIN_1A.M, is called to evaluate DTerr = Ttip - Tinfi as a 
%   function of the fraction of the probe that is immersed into the fluid whose
%   temperature is to be measured. 
%
%   This main routine simply calls PIN_FIN_1A a number of times to perform the 
%   desired sensitivity analysis (vary hi and k).  It also plots the final 
%   results of the analysis for easy visualization.
%
%   This example emphasizes function evaluation, plotting, and the use of 
%   user-defined function files in Matlab.
%
%   The basic idea for this problem came from Prob. 3.110 on pg. 173 in the text  
%   "Fundamentals of Heat and Mass Transfer" 5th Ed by Incropera and Dewitt 
%   (2002, John Wiley & Sons).
%
%   File prepared by J. R. White, UMass-Lowell (last update: Sept. 2017)
%

      clear all,  close all,  nfig = 0;
%
%   identify basic problem data
      Tinfo = 20;                       % outside temperature (C)
      ho = 10;                          % outside heat transfer coeff (W/m^2-C)
      Tinfi = 80;                       % inside temperature (C)
      hi = [1100 550];                  % outside heat transfer coeffs (W/m^2-C)
      k = [177 20];                     % probe's thermal conductivity (W/m-C)
      L = 0.2;                          % overall probe length (m)
      D = 0.0125;                       % probe diameter (m)
%
%   compute DTerr vs Li/L for reference case
      [LiL1,DTerr1] = pin_fin_1a(Tinfo,ho,Tinfi,hi(1),k(1),L,D);
%
%   compute DTerr vs Li/L for low thermal conductivity case
      [LiL2,DTerr2] = pin_fin_1a(Tinfo,ho,Tinfi,hi(1),k(2),L,D);
%
%   compute DTerr vs Li/L for low heat transfer coefficent case
      [LiL3,DTerr3] = pin_fin_1a(Tinfo,ho,Tinfi,hi(2),k(1),L,D);
%
%   plot DTerr vs Li/L for all three cases
      nfig = nfig+1;   figure(nfig)
      plot(LiL1,DTerr1,'r-',LiL2,DTerr2,'g--',LiL3,DTerr3,'b-.','LineWidth',2),grid
      title(['PIN\_FIN\_1:  \DeltaT_{err} vs L_i/L for Several Cases (L = ', ...
            num2str(L*100),' cm)'])
      xlabel('Immersion Length Ratio (L_i/L)')
      ylabel('\DeltaT_{err}  (^oC)')
      legend('Ref. Case','Low k Case','Low h_i Case','Location','SouthEast')
%
%  end of problem