Integration of function with discontinuities given as vector elements with "quadgk"?

I want to integrate a function f, which has discontinuities at the positions given as vector elements x[i] (the length of the vector and its values depends on the particular data set).

I know the “quadgk” offers the possibility for introducing such intermediate interval boundaries at dislocations with the convention:
quadgk(function, x1, x2, x3…; kws…), where the function is integrated from x1 to x2, then from x2 to x3 and so on.
However, the quadgk does not accept boundaries given as vector x such as
quadgk(function, x; kws…)
which gives the error message that it does not fit to the method quadgk(::Any, ::Any, ::Any, ::Any…; kws…).

I don‘t know how to deal with it … probably there is a simple solution to „translate“ my vector elements into the required format, which I don‘t know because it‘s only my second day with julia … can anybody help me?

From your description it sounds like quadgk(f, x...)
should work, where x is your vector and you literally type the three dots.

This is called “splatting”. It expands your vector into independent arguments of the function.


Great, thanks a lot, it seems to work!

1 Like

Glad it worked. Welcome to Julia and this Discourse site!

By the way, you can wrap code in backticks (```).

1 Like