30 views (last 30 days)

Show older comments

Dani Amposta Navarro
on 11 Apr 2021 at 21:05

Commented: Dani Amposta Navarro
on 11 Apr 2021 at 22:49

Is there any function or any other compact and simple form to know if a function is continuos in a interval?

In other math programs you can do it with a siple iscont[function, x=(interval)] and is very very usefull, I don't know why MATLAB can't do this basic and usefull thing.

Matt J
on 11 Apr 2021 at 21:20

It seems like a very hard thing to do, even for the Symbolic Math Toolbox.

John D'Errico
on 11 Apr 2021 at 21:48

It may seem basic to you. However, that just means you need to understand computing and floating point arithmetic.

Nope. In fact, no (non-constant) function when evaluated in double precision can possibly be continuous. This is easy to show, since you cannot evaluate the function at two points that are infinitely close together. You can evaluate the function only at discrete points in terms of the 64 bits of information stuffed into a double.

Essentially, as long as you can do no more than evaluate the function at any point, as a black box, then you can NEVER know if a function is continuous. The idea is I can always create some simple function that is EVERY where continuous, but then insert some infinitessimal discontinuity at a specific location known only to the programmer (me). I'm not telling where. So you will need to test EVERY location in that space, thus 2^64 possible locations along the real line. At every point, you will then need to decide if the function is continuous, perhaps by testing the immediate neighbors along that line.

2^64

What is 1e19? Lets see. There are 30 million seconds in a year. If you can perform a billion such tests per second,

2^64/3e7/1e9

The test would still require something like 614 years to perform.

So as much as the test itself will be painful, requiring 2^64 tests, how will you know if the function is continuous? For example, we can try this out:

x = 1;

dx = eps;

fun = @(x) sin(x.^2);

ftest = fun(x + [-dx,0,dx])

they look the same, yet they are not.

diff(ftest)

Since this is a nonlinear function, how are you to know if I did something very tricky in that black box of a function? You cannot do so. You cannot evaluate the function at closer points than that. And if you look at the function at a sequence of such points, any nonlinear function will in fact look quite bumpy.

diff(fun(x + dx*[-5:5]))

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

Start Hunting!