% Example 14.1a (Physics 330) function s=leastsq(a,x,y) %********************************************************* % leastsq can be passed to fminsearch to do a % non-linear least squares fit of the function % funcfit(a,x) to the data set (x,y). % funcfit.m is built by the user as described here % a is a vector of variable parameters; x and y % are the arrays of data points %********************************************************* % find s, the sum of the squares of the differences % between the fitting function and the data s=sum((y-funcfit(a,x)).^2);