To find the least-squares polynomial of degree 2 in MATLAB, you can use the polyfit function.
Here's an example:
main.m385 chars19 lines
This code fits a polynomial of degree 2 to the x and y data using polyfit, evaluates the fitted polynomial at 100 points between 0 and 6 using polyval, and then creates a plot of the data with the fitted polynomial superimposed.
gistlibby LogSnag