英语好的matlab达人请进
一道题,如题所要求,在线形回归时,不能用polyval或其他functionYou are required to write a program (MATLAB function) that fits a polynomial to a set of
data. Your programme should use the MATLAB command ”polyfit”, however, it should not
use any other built-in polynomial fitting MATLAB functions (such as ”spline”). The call to
the finished function should look like:
[poly, bounds] = linefit(data, norm)
where poly is a row vector of elements pi corresponding to the coefficients of xi in a polynomial
function for y: i.e.
y = p0 + p1x + p2x2 + ...pnxn (1)
bounds = [xmin, xmax] is a vector defining the bounds of the fit (based on the bounds of
the data set). data is data set in the form of a vector of x,y pairs, thus:
data = [x1, y1; x2, y2; ; xn, yn];
and norm takes the string values ’max’ and ’lse’ for maximum norm and least-squares error
norm respectively. The ’max’ norm defines the ’distance’ between the curve fit and the original
data to be the maximum distance between the fitted curve and the curve that results from
fitting a straight line between each successive pair of data points. The ’lse’ norm defines the
’distance’ between the curve fit and the original data to be the total (root-mean squared) area
2
enclosed between the fitted curve and the curve that results from fitting a straight line between
each successive pair of data points.
Your function should find the polynomial of least degree which is best fitted to the data
set under the specified norm: that is, the curve which minimises the ’distance’ between the
polynomial fitted curve and the linear fitted curve as specified by either ’max’ or ’lse’.
You should write a second function disp line(pp, bounds, data) which displays (including
plotting) the results of the fit in an easy to read and understand form.