% This code is a modified version of the code for Problem 9 of Sec. 3.6
%  of the book by C.W. Groetsch, "Inverse problems".

tmax=30;          % length of time window
n=2*60;            % # of discretization points per this window, including its end points
h=tmax/(n-1);     % discretization step size
tt=linspace(0,tmax,n);      % vector of discretization points,
                            %  which has the same length as the solution  u  (see below)
u=log(tt+5)+0.4*tt;    % the solution without noise 
rexact=1./(tt+5)+0.4;  % the exact rate r(t) giving rise to the above solution
ep=0.01;               % amplitude of noise
uep=u+ep*(1-2*rand(1,n));   % the solution perturbed by a small noise of maximum magnitude  ep

for k=1:n-1
	r(k)=(uep(k+1)-uep(k))/h;
end
r(n)=r(n-1);

figure(1011);
plot(tt,r,tt,rexact,'r--','linewidth',2)
legend('numerical','exact')
title('Numerical and exact data r(t)','fontsize',16)


