Double integrals with variable upper limit

Click For Summary
The discussion focuses on computing the double integral F(k) = k∫₀^∞ dy ∫₀^y dx f(kx,y) in C, highlighting the limitations of Python's scipy.integrate.dblquad due to speed issues. A user has attempted to implement a 2D Gaussian quadrature in C but is constrained by the requirement for double limits. Suggestions include using a substitution method to create a finite integration domain and coding a routine that loops through one-dimensional integrals to approximate the double integral. The accuracy of the results can be enhanced by optimizing the integration process based on the function's properties. Additionally, exploring floating point or GPU programming is recommended for further optimization.
niteOwl
Messages
10
Reaction score
0
How can you compute
<br /> F(k) = k\int^{\infty}_{0}dy\int^{y}_{0}dx f(kx,y)<br />

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:
Technology news on Phys.org
niteOwl said:
How can you compute
<br /> F(k) = k\int^{\infty}_{0}dy\int^{y}_{0}dx f(x,y)<br />

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?

This is k times a constant, which happens to be \int_0^\infty \int_0^y f(x,y)\,dx\,dy. You can obtain a rectangular, finite domain of integration by making the substitution (x,y) = (\mathrm{arctanh}(s) \cos\theta, \mathrm{arctanh}(s) \sin \theta) to obtain <br /> \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. Probably best to use a scheme of integration which doesn't require values of the integrand on s = 1.
 
pasmith said:
This is k times a constant

i forgot to say the integrand also depends on k, question is edited.
 
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 16 ·
Replies
16
Views
6K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
7K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K