Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C/++/# Double integrals with variable upper limit

  1. Jul 5, 2016 #1
    How can you compute
    F(k) = k\int^{\infty}_{0}dy\int^{y}_{0}dx f(kx,y)

    in C. I know about Python's scipy.integrate.dblquad function but it's just too slow. I have written some Cython code with a 2D gaussian quadrature function in C but it only takes doubles as limits. I think C doesn't have anything like Python's lambda, so how can this be done in C?
    Last edited: Jul 5, 2016
  2. jcsd
  3. Jul 5, 2016 #2


    User Avatar
    Homework Helper

    This is [itex]k[/itex] times a constant, which happens to be [itex]\int_0^\infty \int_0^y f(x,y)\,dx\,dy[/itex]. You can obtain a rectangular, finite domain of integration by making the substitution [itex](x,y) = (\mathrm{arctanh}(s) \cos\theta, \mathrm{arctanh}(s) \sin \theta)[/itex] to obtain [tex]
    \int_0^1 \int_{\frac14\pi}^{\frac12\pi} \frac{\mathrm{arctanh}(s)}{1 - s^2} f(\mathrm{arctanh}(s) \cos\theta, \mathrm{arctanh}(s) \sin \theta)\,d\theta\,ds.[/tex] Probably best to use a scheme of integration which doesn't require values of the integrand on [itex]s = 1[/itex].
  4. Jul 5, 2016 #3
    i forgot to say the integrand also depends on k, question is edited.
  5. Jul 6, 2016 #4


    User Avatar
    Science Advisor

    Hey niteOwl.

    You could theoretically code a routine that loops through the one dimensional integrals and adds them up to achieve a double integral.

    If you can integrate one "strip" (as it were) you just add up the strips in the double integral.

    The accuracy will be determined with respect to the kind of function being integrated and if you know various derivative properties you could optimize it so that you only do so many computations per evaluation and that gets processed in some finite time interval. If you do this so many times within a couple of loops then you will be able to gauge the computational complexity of the integration routine.

    If you want to optimize further then try learning floating point or GPU programming as an exercise.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: Double integrals with variable upper limit
  1. Global variables. (Replies: 7)