function gradient = expdecaygradient(t, x, tau)
% Gradient of MSE for a decaying exponential.
%
% Arguments: t, vector of time points.
%            x, vector of the corresponding measured data values.
%            tau, value for the time constant. 
%
% Returns: gradient: the derivative of the MSE with respect to tau.
  h = 1e-7;   % stepsize for derivative
  gradient = (expdecaymse(t, x, tau+h) - expdecaymse(t, x, tau))/h;
end