function [y, err, w] = mark_lin(w, x) % mark time series x, the linear function % % [idx, w, err] = mark_lin(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 % err [scalar] the residual variance, MSE % w [1,W] parameters of the function % % if the regression parameters are required, the Least Squares Method will % be called, and the parameters will be returned together with new MSE. % Example % x = [1; 2; 3; 4; 5] % w = [0.1 1.1] % [y, err] = mark_lin(w, x) % [y, err, w] = mark_lin(w, x) m = length(x); if nargout > 2 w = lscov( [ones(size(x)), [1:m]'], x ); end y = w(1) + w(2) * (1:length(x))'; r = x-y; err = ((r'*r) / m); return