MATLAB Answers

argument vector for smooth function plots

1 view (last 30 days)
Ilya on 19 Mar 2014
Edited: Ilya on 3 May 2014
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.


Ilya on 20 Mar 2014
I suspect that the derivatives could be used somehow, but I don't no how to use them in a good way...
Ilya on 20 Mar 2014
The problem is also not about data interpolation, i.e. splines are not the solution. And the 30th degree is only an example for "high degree". In fact, the degree of polynomials can be constrained to a realistic value, if needed.

Sign in to comment.

Accepted Answer

Ilya on 20 Mar 2014
Edited: Ilya on 1 May 2014
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.
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..


Show 1 older comment
Ilya on 24 Mar 2014
Actually, yes. But I'm not sure that it always works properly and also I suspect that there may be some more elaborated approaches for polynomials and other infinitely differentiable functions. It is even interesting to know what other approaches are possible. But now I'm using fplot().
John D'Errico
John D'Errico on 2 May 2014
You THINK this is a reasonable thing to do, to work with high order polynomials in double precision. However, one day you will realize that you were kidding yourself.
Sorry, but working with polynomials of that high of an order (20-30) in double precision is a foolish thing to do in general. You MAY be successful with lower orders, depending on the domain of interest.
I see that you accepted your own answer, so you clearly know everything already.
Ilya on 3 May 2014
Dear John,
I don't think anything. I only said that it's possible to make the problem better conditioned by using the Chebyshev basis. Then it might be possible to work in double with slightly higher polynomial orders. As for orders, I'm using Advanpix Multiprecision Computing Toolbox (I said this in the initial problem formulaton, but then removed), which has the fast quadruple precision mode. Anyway, I need to use moderately high order polynomials, and not for the purpose of interpolation.
As for the rest of the methodology, finding extrema and plotting between them seems to be the only sane alternative. And I "accepted" long ago that "No, I'm quite sane", "the answer" addition came much later.
I'm sad to write this... I know nothing and I'm stupid that's why I never write about other people that they're insane (although, I know why you did this.. don't worry and nevermind, I understand it)

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 20 Mar 2014
Use of 30'th degree polynomials is insane, at least in double precision. Period. INSANE.
If you are worried about accuracy, perhaps there is a reason why. Oh, that is right, you are using insanely high order polynomials.
Learn to use splines instead. Regain some degree of sanity.

  1 Comment

Ilya on 20 Mar 2014
Is it a suggestion to use splines instead of high order polynomials for interpolation (if so, my problem is for sure not in interpolation), or do you mean that splines have some other usages that сan be helpful here?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!