MATLAB Answers

Curve tolerance between the calculated points

6 views (last 30 days)
Ilya
Ilya on 6 Feb 2014
Edited: Ilya on 6 Feb 2014
In order to plot a curve in MATLAB a set of points is calculated based on some formula. The function FPLOT also supports plotting with some tolerance. Its help says the following about this functionality:
The FPLOT function begins with a minimum step of size (XMAX-XMIN)*TOL.
The step size is subsequently doubled whenever the relative error
between the linearly predicted value and the actual function value is
less than TOL.
So, if I plot a curve based on some expression and with some predefined tolerance TOL, is the error of the line segment approximation between any two calculated points always smaller than TOL?
Sorry, this is not obvious for me.
A confident yes/no answer would suffice, but it's also better to explain the reason and/or give an estimate for the maximal error of approximation of a curve with linear segments if a tolerance algorithm like in FPLOT is used.

  4 Comments

Show 1 older comment
Ilya
Ilya on 6 Feb 2014
Sorry, the excerpt is from the function file fplot.m. I can delete it (or a forum administrator can do this..) if such excerpts are not allowed. I really was not aware if this were not allowed.
John D'Errico
John D'Errico on 6 Feb 2014
To be honest, I was not impressed with the help for fplot. I found it quite a bit confusing as to the purpose of the code, the requirements on the function, and all this even for a highly experienced MATLAB user like me.
Matt J
Matt J on 6 Feb 2014
I can delete it (or a forum administrator can do this..) if such excerpts are not allowed.
No, I meant you should provide a link to it so that we can know where to find it and read its full text. It wasn't in the help doc...

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 6 Feb 2014
Edited: John D'Errico on 6 Feb 2014
No. You cannot know the maximum error of approximation between parts of the curve that were not sampled. I can always give you any simple (and very well behaved) curve, plus a delta function in some spot that will not have been sampled. The error of approximation can then be arbitrarily large, and fplot will never know it.
Of course, the curve I suggested as a counter-example will not be continuous or even differentiable. However, if you want that property and still see fplot "fail" to see that spike, then just add a Gaussian instead of a delta function to the well-behaved function, but choose a Gaussian with an extremely small width. As such, it behaves like a delta function, but is still theoretically infinitely differentiable.
Thus you cannot assure that the error will ALWAYS be smaller than tol, for any supplied tolerance. This is a fundamental issue with virtually any computational algorithm when applied to a completely general function. You can always choose some (locally degenerate) function that will cause it to "fail" to achieve a given tolerance.

  3 Comments

Ilya
Ilya on 6 Feb 2014
This sounds very sound. Thanks a lot. And what if the function is several times differentiable (e.g. sin(nx), cos(mx) or a linear combination of sin(nx), cos(mx)) and there is no "noise" (e.g. n and m in sin(nx), cos(mx) are less than some small integer, say 5 or 10). Can some bounds be guaranteed for this case? Or, at least, do some bounds on the error of "piecewise-linear" approximation exist in this case if a tolerance algorithm like in FPLOT is used?
John D'Errico
John D'Errico on 6 Feb 2014
Again, consider my counter-case, wherein a linear function plus a narrow Gaussian will result in arbitrarily large errors. The composite function is infinitely differentiable, yet will allow no bounds on the error.
If you choose some set of infinitely differentiable functions (i.e., your trig example) but where the derivatives are LIMITED IN MAGNITUDE ove the domain of interest, then yes you can probably ensure that the tolerance is met.
Ilya
Ilya on 6 Feb 2014
Thanks a lot, this is now a quite complete information about the topic.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!