function E = gg250_lab9_misfit (x, y, a, b, mode) % GG250_LAB9_MISFIT Calculate misfit of a straight line % % E = gg250_lab9_misfit (x, y, a, b, mode) % Input % x, y: a set of (x,y) coordinates % a, b: Coefficients for the line y = a*x + b % mode: How to measure misfit: % 0 = Mean Square of vertical distances % Output: % E: The measure of misfit in units of y-squared. e = y - (a.*x - b); % The residuals E = sum (e .* e) / length (e);% Mean squared error