Numerical integration - Fourier transform or brute force?

Click For Summary

Discussion Overview

The discussion focuses on optimizing numerical integration techniques for a specific integral involving a function f(k) and its relationship with the sine function. Participants explore various methods, including Fourier transforms and different numerical integration techniques, while addressing the challenges posed by oscillatory integrands and the need for interpolation.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes using the trapezoidal method for numerical integration but expresses a desire for more sophisticated techniques like polynomial or spline integration.
  • Another participant suggests using a linear interpolation of f(k) between sample points and integrating mathematically for each trapezoid, providing a formula for the integral of the linear function multiplied by sine.
  • A different participant mentions the use of the Discrete Fourier Transform (DFT) algorithm but notes discrepancies in results compared to the trapezoidal method.
  • Several participants propose alternative algorithms, including Andrew Hamilton's FFTLog algorithm, QAWO routine from QUADPACK, and a method called "dftint" from Numerical Recipes.
  • One participant introduces Gauss-Hermite Integration as a method for approximating integrals of a specific form, referencing resources for further information.
  • Another participant questions the accuracy of the trapezoidal method compared to other methods and seeks clarification on the advantages of using FFT.

Areas of Agreement / Disagreement

Participants express a variety of approaches and opinions regarding numerical integration methods, with no consensus on a single best method. Some participants agree on the challenges posed by oscillatory integrands, while others propose different solutions without resolving the overall debate.

Contextual Notes

Participants note the dependence of their methods on the specific properties of the function f(k) and the challenges of integrating over infinite limits, which may affect the applicability of certain techniques.

Who May Find This Useful

Readers interested in numerical methods for integration, particularly in the context of physics and engineering applications, may find the discussion valuable.

coccoinomane
Messages
19
Reaction score
0
Hi everybody!

I kindly request your help in optimizing the numerical integration of the following expression:

[tex]\xi (r)=\frac{1}{2\pi ^2}\int_{-\infty}^{\infty}f(k)\cdot \sin(k\cdot r)\cdot dk[/tex]

[tex]f(k)[/tex] vanishes outside the boundaries k=0 and k=2; I have got [tex]k[/tex] and [tex]f(k)[/tex] as float arrays, so we are talking about a numerical problem.

I obtained [tex]\xi (r)[/tex] by using the trapezoidal integration method. I would have loved to use something more sophisticated such as polynomial or spline integration, but I could not find anything written in C++ to do that.

The problem with the brute force approach is that sin(kr) make the integrand function oscillate wildly at high r's. Therefore, I need to interpolate the [tex]f(k)[/tex] in order to have enough points (~millions) over which to integrate. This is very time consuming and pretty inelegant, as brute force always is :)

I tried a more "intelligent" approach by expanding

[tex]\sin (k\cdot r)=\frac{\exp(ikr)-\exp(-ikr)}{2i}[/tex]

and then computing the resulting expression

[tex]\xi (r)=\frac{1}{4\pi^2 i}\cdot\left(\int f(k)\cdot \exp(ikr)\cdot dk - \int f(k)\cdot \exp(-ikr)\cdot dk\right)[/tex]

making use of the Discrete Fourier Transform algorithm in Octave and Matlab. This way, however, I do not have any idea on how to relate the output array ([tex]\xi(r)[/tex]) with the r's. Furthermore, I compared the results I obtained with the brute force solution and it turned out that the DFT algorithm solution was wrong.

Here are my questions:
1) is it possible to solve the above integral by making use of some Fourier transform algorithm?
2) if this is not the case, can somebody suggest me a numerical integration method more effective than the trapezoidal one?

Thank you very much for reading this long post :)

Cheers

P.S. this is not homework.
 
Physics news on Phys.org
Hi,

did I omit some important information? Or maybe I posted in the wrong forum?

By the way, I found a routine in the GNU Scientific Library called "QAWF adaptive integration for Fourier integrals" that could be what I am looking for. I only need to get acquainted with GSL, and it is going to take some time.

Any advice is still welcome :)

Ciao,

Guido
 
Are you trying to do a numerical integration over doubly infinite limits? How do you propose to pull that off?
 
Dr.D said:
Are you trying to do a numerical integration over doubly infinite limits? How do you propose to pull that off?

Hi Dr.D, thank you for the answer.

The function f(k) vanishes for k<0 and k>2, so the infinite integration limits should not be a problem.
 
Sorry I overlooked that part of the problem statement. All I saw was that infinite integral.

You might want to look at an old book from about 1970 titled Numerical Methods that Work (the author's name slips away from me right now).
 
Last edited:
coccoinomane, why don't you just make a linear interpolation of f between sample points and integrate (not numerically but mathematically in closed form) for each of these trapezoids.

That is, between f(k) and f(k+1) use :

[tex]f(x) = f_k + \frac{(f_{k+1}-f_k) \, (x-x_k)}{(x_{k+1} - x_k)} = ax + b[/tex]

Now you can integrate [itex](ax + b) sin(rx) dx[/itex] easily enough for each of these linear regions.

BTW.
[tex]\int x \sin(rx) \, dx = \frac{\sin(rx)}{r^2} - \frac{x \cos(rx)}{r}[/tex]
 
uart, thank you very much for the idea! This way I can evaluate the integral almost analytically.
I am trying a slightly modified version of your approach by using a Splines interpolation of f(k) instead of a linear one; I will let you know the outcome. By the way, do you have any idea on how to quantify the error this way?

Thank you again, you saved my day :)

Cheers,

Guido

uart said:
coccoinomane, why don't you just make a linear interpolation of f between sample points and integrate (not numerically but mathematically in closed form) for each of these trapezoids.

That is, between f(k) and f(k+1) use :

[tex]f(x) = f_k + \frac{(f_{k+1}-f_k) \, (x-x_k)}{(x_{k+1} - x_k)} = ax + b[/tex]

Now you can integrate [itex](ax + b) sin(rx) dx[/itex] easily enough for each of these linear regions.

BTW.
[tex]\int x \sin(rx) \, dx = \frac{\sin(rx)}{r^2} - \frac{x \cos(rx)}{r}[/tex]
 
Hi Everybody!

I am raising this post from the dead just to list a few algorithm I used with success to integrate the above function:

1) Andrew Hamilton's FFTLog algorithm from http://casa.colorado.edu/~ajsh/FFTLog/. It permits you to integrate not only f(x)*sin(x) but any integrand in the form f(x)*J_u(x) where J_u(x) is the u-th order regular Bessel function. The only downsize it's that it is written in Fortran 77.

2) QAWO routine from QUADPACK. A C version is contained in the GNU Scientific Library (http://www.gnu.org/software/gsl/) while a Fortran 77 version can be downloaded from Netlib (http://www.netlib.org/quadpack). It's a rock solid package that has been tested over the years.

3) Numerical Recipes C++ routine called "dftint" (Discrete Fourier Transform INTegration). It can be found on page 692 of Numerical Recipes 3rd edition; alas it is not free software.

If you need any clarification or help with the above algorithms please feel free to send a Personal Message to me or to e-mail me at coccoinomane gmail dot com.

Cheers,

Guido
 
Last edited by a moderator:
There is a method: "Gauss-Hermite Integration" to approximate integrals of the form

[tex] \int_{-\infty}^{\infty} \exp(-x^{2}) f(x) dx = \sum_{i=1} ^{N} w_{N,i} f(x_{i})[/tex]

The N grid point x_{i} can be obtained as the zeros of the N -point Hermite polynomial

find the w_{N,i} in tables

Search the book: Applied Numerical Methods Using MATLAB - Yang Cao Chung and Morris
 
  • #10
This looks like the sine Fourier transform of a reciprocal space total scattering function into real space.

I'm interested in knowing how the results from using a trapezoidal integration compare to that of the other methods you found? The trapezoidal integration method is an approximation but is it a good approximation? And why is using FFT better, is it just more accurate?

cheers.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 7 ·
Replies
7
Views
5K