%
%   RECT1D_FIN_3A.M   Function file to compute the coefficient matrices (A & b) 
%                    for the nonlinear rectangular fin heat transfer problem.  
%
%   This routine is called from RECT1D_FIN_3.M.  Several variables are passed 
%   into this routine via input arguments, but only the convective heat transfer 
%   coeff is position dependent --  this is the only term that varies with each call 
%   to this function.  The desired A and b coefficient matrices are returned.  
%
%   File prepared by J. R. White, UMass-Lowell (last update:  Nov. 2017)
%

      function [A,b] = rect1d_fin_3a(h,Tb,Tinf,k,L,w,thk,N)
%
%   initialize variables
      dx = L/N;   dx2 = dx*dx;   
      A = zeros(N,N);   b = zeros(N,1);
%
%   compute m2 variable (this is space dependent because h is a function of space)
      P = 2*w + 2*thk;                  % perimeter
      Ac = w*thk;                       % cross section area (conduction area)
      m2 = h*P/(k*Ac);                  % parameter in derived equations (see notes)
%
%   compute coeff matrices
%   node 1
      A(1,1) = -(2 + m2(1)*dx2);  A(1,2) = 1;  b(1) = -m2(1)*dx2*Tinf - Tb;
%   interior nodes
      for i = 2:N-1
        A(i,i-1) = 1;  A(i,i) = -(2 + m2(i)*dx2);  A(i,i+1) = 1;  
        b(i) = -m2(i)*dx2*Tinf;
      end
%   node N
      A(N,N-2) = 1;  A(N,N) = -(2*m2(N)*dx2 + 1 + 2*h(N)*dx/k);
      b(N) = -(2*h(N)*dx/k + 2*m2(N)*dx2)*Tinf;
%
%   end of routine
