% TestLinfit.m Feb. 2005 L Braile % Test and plot the linfit least squares straight % line function with sample data x = [1 2 3 4 5 6 7 8 9]; y = [1.5 1.8 2.0 3.6 4.1 6.8 6.4 4.0 9.4]; mode = 0; npts = length(x); sigmay = ones(1,npts); % assume uncertainties in y are all = 1 % calculate and print least squares coefficients, sigmas and r [a,sigmaa,b,sigmab,r] = linfit(x,y,sigmay,npts,mode) % plot the data and least squares line plot(x,y,'ro','markersize',12,'linewidth',3) % Plot the data set(gca,'fontsize',16,'linewidth',2) hold on xlabel('x-values','fontsize',16) ylabel('y-values','fontsize',16) title('Plot of sample data and least squares straight line fit','fontsize',16) yt = feval('sline',x,a,b); % Calculate the fitted line plot(x,yt,'k-','linewidth',3) % Plot the fitted line axis([0 10 0 10]); % Set axis limits for plot hold off