MATLAB: Argument vector for smooth function plots

accuracyMATLABplotpolynomial

Hello,
I have arbitrary polynomial functions y=f(x) of a degree, say, N<30 and need to plot them over some predefined interval of x. Is it possible to choose the vector of x so that this particular type of function (i.e. polynomials) is plotted "smoothly", i.e. that there's no big accuracy differences between the intervals of a large slope and small slope of y?
If I simply choose x with some constant step, then some parts of the curve will be very accurate while the others will be inaccurate.
An expert opinion is also valuable because the speed is an issue, i.e. it's better not to call the diff function 1000 times, if possible.

Best Answer

No, I'm quite sane. The degree of 30 is only an example of a high degree. Normally, the degree is 4-15, at max. 20.
If there are some precision problems due to high polynomial orders, then the max. order can be constrained (I hope the orders of 4-10 are still manageable in double..).
My problem is also not about data interpolation (i.e. splines are not considered). I'm really concerned that some important parts of a curve may be skipped during the plotting, if an unreasonable argument vector is selected. The "plotting" happens automatically into a file, so I don't have the visual control of the results.
THE ANSWER:
Differentiate the polynomial (polyder) and find the zeros of the derivative (roots). These zeros will be the critical points for the plot, take all other sample points between them.
Polynomial rootfinding and evaluation can be performed in Chebyshev basis instead of the "calssical" monomial/power one. See Clenshaw algorithm for polynomials in Chebyshev basis. The accuracy in Chebyshev basis is typically higher then of the monomial one. Alternatively, use precision better then double..
Related Question