% This script minimizes (T(t) - a C(t - tau))^2 by finding a and tau.
% It minimizes function LagError with Fmins.  It returns a variable ctdlag:
%    ctdlag(1) = optimum C
%    ctdlag(2) = optimum tau
%
% J. G. Bellingham

k = [12.6 -0.4];
ctdlag = fmins('LagError', k, 0, [], data, m_present_time, water_temp, water_cond);