There is no fixed rule to determine the order of polynomial. However, we can use the following methods to determine the best order of polynomial in MATLAB:
Visual Inspection: Plot the data and observe the trend. If the data points seem to follow a linear trend, then a first-order polynomial is sufficient. If the data points seem to follow a curve, then a second or higher-order polynomial may be needed.
Residual Analysis: Calculate the residual for each polynomial degree and choose the degree with the lowest residual values.
Here is an example code that demonstrates how to apply the above methods:
main.m383 chars23 lines
The first figure shows the scatter of the example data, while the second figure shows the SSE values for various polynomial degrees. Based on both visual inspection and residual analysis, we can see that a second-order polynomial is the best fit for this particular data.
gistlibby LogSnag