function [y, err, w] = mark_exp(w, x)
% mark time series x, the exponential function
%
% [idx, w, err] = mark_exp(w, x)
%
% w [1,W] parameters of the model here y = w(1) + w(2)*x;
% x [m,1] time series, the depended variable of the regression fit 
%
% y [m,1] the calculated depended variable
% mse [scalar] the residual variance, MSE
% w [1,W] parameters of the function
%
% if the regression parameters are required, the Levenberg_Markquardt Method will
% be called, and the parameters will be returned together with new MSE.

% Example
% x = [298; 294; 284; 272; 260; 248; 238; 226; 216; 206; 196; 186; 178; 170; 162; 154; 148; 140; 134; 128; 122; 118; 112; 108; 102;  98;  94;  90;  88;  84;  80;  78;  76;  72;  70;  68;  66;  64;  62;  60;  58;  56;  56;  54;  54;  52;  50;  50;  48;  48;  48;  46;  46;  46;  46;  44;  44;  44;  44;  42;  42;  42;  42;  42;  40;  40;  40;  40;  40;  40;  40;  40;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38;  38];
% w = [[30 300 -0.05]]
% [y1, err] = mark_exp(w, x)
% [y2, err, w] = mark_exp(w, x)
% tim = [1:length(x)]';
% figure; hold on
% plot(tim, x, 'k.');
% plot(tim, y1, 'b-');
% plot(tim, y2, 'r-');
% legend('source', 'manual parameters', 'optimised parameters');
% xlabel('time'); ylabel('value');

f = inline('w(1) + w(2) * exp(w(3) * (1:length(x))'')', 'w', 'x');
if nargout > 2
    w = nlinfit((1:length(x))', x, f, w);
end
y = f(w,x);
r = x-y;
err = ( (r'*r) / length(x) );   
return
