# Finding jumps/discontinuities in a univariate function

**URL:** <https://discourse.julialang.org/t/finding-jumps-discontinuities-in-a-univariate-function/13919>\
**Category:** Numerics\
**Tags:** question\
**Created:** [August 23, 2018, 7:13am UTC](https://discourse.julialang.org/t/finding-jumps-discontinuities-in-a-univariate-function/13919 "2018-08-23T07:13:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 23, 2018, 7:13am UTC](https://discourse.julialang.org/t/finding-jumps-discontinuities-in-a-univariate-function/13919/1 "2018-08-23T07:13:10Z")

</div>

I want to find jumps (or at least one jump, if it exists) in a univariate function on a given interval. Eg looking for a jump in

```julia
f(x) = x > 0 ? one(x) : zero(x)

```

on [-2,2] should give me \approx 0.

I searched the literature and found that this is called “edge detection” in image processing, but in contrast, I can readily evaluate the function just anywhere, also, I just need univariate. I have no derivatives (that I would trust).

I am aware that such algorithms are heuristic, may not find edges and may return bogus ones. This is just needed for a plotting problem though. I am not familiar with these algorithms and thought of asking before devising my own, so suggestions for specific Julia packages, or papers/textbooks to read, would be welcome.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [August 23, 2018, 7:22am UTC](https://discourse.julialang.org/t/finding-jumps-discontinuities-in-a-univariate-function/13919/2 "2018-08-23T07:22:13Z")

</div>

I don’t know if a Julia implementation, but Chebfun has a nice algorithm for doing this. I believe it’s built on using bisection, so if you only need one jump should be easy to implement.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [August 23, 2018, 7:55am UTC](https://discourse.julialang.org/t/finding-jumps-discontinuities-in-a-univariate-function/13919/3 "2018-08-23T07:55:50Z")

</div>

Can you look for large absolute values of diff(x)?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 23, 2018, 8:00am UTC](https://discourse.julialang.org/t/finding-jumps-discontinuities-in-a-univariate-function/13919/4 "2018-08-23T08:00:01Z")

</div>

After some digging, I found the algorithm described in

```nohighlight
@article{pachon2010piecewise,
  title={Piecewise-smooth chebfuns},
  author={Pach{\'o}n, Ricardo and Platte, Rodrigo B and Trefethen, Lloyd N},
  journal={IMA journal of numerical analysis},
  volume={30},
  number={4},
  pages={898--916},
  year={2010},
  publisher={OUP}
}

```

Specifically, it is `detectedge(f, a, c)` on page 8, and is conceptually very simple: calculate f, f', f'', f''' by differences on a grid, select the largest one, refine that cell, and see if the derivatives increased. I should be able to adapt this easily for my purposes.

@dpsanders: This is what the above method uses, except with a recursive refinement.

Thanks for all the help.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [August 23, 2018, 8:20am UTC](https://discourse.julialang.org/t/finding-jumps-discontinuities-in-a-univariate-function/13919/5 "2018-08-23T08:20:32Z")

</div>

Great! If you implement it, I might incorporate it into ApproxFun.
