Double integrals with variable upper limit

In summary, the code could be optimized to do fewer evaluations per function call, which would reduce the overall time needed to complete the task.
  • #1
niteOwl
10
0
How can you compute
[itex]
F(k) = k\int^{\infty}_{0}dy\int^{y}_{0}dx f(kx,y)
[/itex]

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
  • #2
niteOwl said:
How can you compute
[itex]
F(k) = k\int^{\infty}_{0}dy\int^{y}_{0}dx f(x,y)
[/itex]

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 [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].
 
  • #3
pasmith said:
This is [itex]k[/itex] times a constant

i forgot to say the integrand also depends on k, question is edited.
 
  • #4
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.
 

Related to Double integrals with variable upper limit

1. What is a double integral with variable upper limit?

A double integral with variable upper limit is a mathematical concept used in multivariable calculus. It involves integrating a function of two variables over a specific region in the xy-plane, where the upper limit of integration changes depending on the value of the other variable.

2. How is a double integral with variable upper limit different from a regular double integral?

In a regular double integral, the upper and lower limits of integration are constant values. In a double integral with variable upper limit, the upper limit of integration is a function of the other variable, making the integration more complex.

3. What is the significance of using a variable upper limit in a double integral?

Using a variable upper limit allows us to integrate over non-rectangular regions in the xy-plane, which cannot be done with a regular double integral. It also allows us to evaluate the integral more accurately, as the upper limit can be adjusted to fit the shape of the region.

4. How do you set up and solve a double integral with variable upper limit?

To set up a double integral with variable upper limit, you first need to determine the region of integration and the function to be integrated. Then, you need to express the upper limit of integration as a function of the other variable. Finally, you can evaluate the double integral using standard integration techniques.

5. In what real-world applications are double integrals with variable upper limit used?

Double integrals with variable upper limit have various applications in physics, engineering, and economics. They are used to calculate volumes, surface areas, and mass in three-dimensional systems. They also play a crucial role in calculating work, fluid flow, and probability in various real-world scenarios.

Similar threads

  • Programming and Computer Science
Replies
1
Views
809
  • Programming and Computer Science
Replies
7
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
19
Views
2K
  • Calculus and Beyond Homework Help
Replies
2
Views
283
  • Programming and Computer Science
Replies
1
Views
671
  • Programming and Computer Science
Replies
16
Views
4K
  • Programming and Computer Science
Replies
1
Views
987
  • Programming and Computer Science
Replies
1
Views
701
Back
Top