%--------------------------------------------------------------------- %function [h, outlier, outlier_index] = experiment_least_squares(A, b) % % Matlab function to compute a least squares fit for more general % data than the hill-height problem in experiment_least_squares1.m % %----------- % On entry, %----------- % A is a m x n matrix with entries corresponding to the linear model % b is a n x 1 vector with the observed % %------------ % On return, %------------ % h = best fit parameters % outlier = observation value that is worst fit % outlier_index = index of observation value that is worst fit % % Started : Sun 8 Feb 2009 % Modified : Wed 11 Feb 2009 % %--------------------------------------------------------------------- function [h, outlier, outlier_index] = experiment_least_squares(A, b) h = A\b; residual = b - A*h; [outlier, outlier_index] = max(abs(residual)); return