Hey guys, uni major assignement due dates are coming up and one of these is 'matlab' It's an engineering program, and I really need help with my assignement. This is what we have to do:
Mech 1820 Matlab
MATLAB Programming Assignment Suresh Kumar, May 2003
The Assignment
You 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=f(x)= pnxn+pn-1xn-1+ … + p1x +p0
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 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.
Marking Scheme (from 40):
15 marks for the algorithm ‘linefit’; the correct solution and structure.
10 marks for error checking and usability
10 marks for comments and documentation
5 marks for function ‘disp_line’
If any of you guys can help me I'd be stoked