function y_hat = lm_func(t,a,c)
% y_hat = lm_func(t,a,c)
%  
% three example functions used for nonlinear least squares curve-fitting
% in the tutorial file lm_examp.m
% to demonstrate the Levenberg-Marquardt function, lm.m
%
% -------- INPUT VARIABLES ---------
%  t     = independent variable values (assumed to be error-free)        (m x 1)
%  a     = parameter values , n = 4 in these examples                    (n x 1)
%  c     = an optional set of model constants
% 
% ---------- OUTPUT VARIABLES -------
% y_hat  = curve-fit fctn evaluated at points t and with parameters a    (m x 1)
%
% H.P. Gavin, Dept. Civil & Environ. Eng'g, Duke Univ.

example_number = c{1};  % an optional set of constants passed to lm_func(t,a,c)

%  example 1:  easy for LM ... a poor initial guess is ok
if example_number == 1
   y_hat = a(1)*exp(-t/a(2)) + a(3)*t.*exp(-t/a(4));
end

%  example 2: medium for LM ... local minima
if example_number == 2
   mt = max(t);
   y_hat = a(1)*(t/mt) + a(2)*(t/mt).^2 + a(3)*(t/mt).^3 + a(4)*(t/mt).^4;
end

% example 3: difficult for LM ... needs a very good initial guess
if example_number == 3
   y_hat = a(1)*exp(-t/a(2)) + a(3)*sin(t/a(4));
end

% LM_FUNC ------------------------------------ 13 Apr 2011, 27 Jun 2011
