% Function returning transient temperature field in semi-infinite solids (Table 2-3) 
function [T, Eta, TT] = Tsemi(surf,x,t)
  bc=surf{1};
  a=surf{2};
  Ti=surf{end};
  x=x(:)'; t=t(:);
  Eta=bsxfun(@rdivide,x,2*sqrt(a*t));
  switch bc
  case 'Ts'
    Ts=surf{3};
    TT=erfc(Eta);
    T=Ti+(Ts-Ti)*TT;
  case 'qs'
    k=surf{3};
    qs=surf{4};
    xErfcEta=bsxfun(@times,x,erfc(Eta));
    TT=(bsxfun(@times,sqrt(4*a/pi*t),exp(-Eta.^2))-xErfcEta);
    T=Ti+qs/k*TT;
  case 'h'
    k=surf{3};
    h=surf{4};
    Tinf=surf{5};
    TT=(erfc(Eta)-exp(h/k*x+(h/k)^2*a*t).*erfc(Eta+h/k*sqrt(a*t)));
    T=Ti+(Tinf-Ti)*TT;
  otherwise
    error('bc=''Ts'', ''qs'' or ''h''');
  end
end
