% Semi-infinite body
% temperature response to a varying heat flux q(t)
% Integral Equation model
clear
tau=1.; y0=0.4;dt=tau/10;nf=200;
figure(1); clf;
for n=1:nf
   axet(n)=tau*dt*n;
  if n<11
      q(n)=n;
  elseif  n<31
    q(n)=20-n;
 elseif n<41
     q(n)=-40+n;
   else
      q(n)=0;
   end
end

plot(axet,q, 'linewidth', 1.0)
hold on


for n=1:nf
   s=0;tn=n*dt;
   for i=1:n-1
      ti=i*dt;
      s=s+impulse(tn-ti,tau)*q(i);
   end
   T(n)=y0*s;
end

plot(axet,T,'r', 'linewidth', 1.0)
 xlabel('t^* = \tau/t = x^2/4\alphat')
 ylabel('\eta, q(t)')
 text(3.7,-6,'q(t)')

%  fig=figure(1);
%  print(fig,fullfile(pwd, 'Figure6_4.tif'),'-dtiff','-r600')

function y=impulse(t,tau)
% temperature response 
% to the heat flux impulse 
% the semi-infinite heat conduction
% tau =x^2^/4a, 
if t<0.0001
      y=0;
else
     tt=tau/t;y=sqrt(tt)*exp(-tt);
end

end
