Least Square Codes

Here you can download the Matlab function file lsquare.m and the (driver) script file run_lsquare.m.


1) The function file lsquare.m receives two column vectors of data as input and generates  intercept b, slope m, and error term E of a least square fit of the data to a straight line y=b+m*x as output. Function call:


In addition data and fitted model line are plotted. Save the file and call it in the workspace or from a script file.

2) The script file run_lsquare.m is the driver file for  lsquare.m. In its present form it solves Problem 5.4(a).