6 views (last 30 days)

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.

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.

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.

Opportunities for recent engineering grads.

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

Start Hunting!
## 4 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/115093-curve-tolerance-between-the-calculated-points#comment_194795

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/115093-curve-tolerance-between-the-calculated-points#comment_194795

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/115093-curve-tolerance-between-the-calculated-points#comment_194807

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/115093-curve-tolerance-between-the-calculated-points#comment_194807

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/115093-curve-tolerance-between-the-calculated-points#comment_194810

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/115093-curve-tolerance-between-the-calculated-points#comment_194810

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/115093-curve-tolerance-between-the-calculated-points#comment_194825

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/115093-curve-tolerance-between-the-calculated-points#comment_194825

Sign in to comment.