6

I have a logarithmic grid, upon which i have two functions that are similar to this one (this is only the last 100 points):

enter image description here

These are essentially very similar to a Sin function at this point. I need to take the integral of two of these functions multiplied together, along with the position:

$$ \int_0^R f_1(r)\; r\; f_2(r)\; dr $$

Unfortunately, this gives me functions similar to the following:

enter image description here

I need to integrate these with high accuracy, but I'm not sure how to do it. There are a few options that I know of, but I expect there are more that I'm not sure of:

  • I can interpolate the original functions (is cubic interpolation a good interpolation strategy for sinusoids and products of sinusoids?), then multiply the interpolated functions together at specific points and use something from this scicomp post

  • I can switch the order of the interpolation and multiplication, multiplying the values I have, then taking the interpolation.

  • I can do a simpler Simpsons rule approximation, though I'm not sure how to do such a thing on a non-uniform grid.

Andrew Spott
  • 1,155
  • 1
  • 9
  • 22
  • Can you write out the form of the function, or is it a black box? – Bill Barth Feb 07 '14 at 23:01
  • @BillBarth: Unfortunately, it is a black box. – Andrew Spott Feb 07 '14 at 23:11
  • Are the functions periodic, or you understand how they are not periodic if so? If they're periodic, taking the Fourier transform and analytically integrating the trigonometric polynomial will give very high accuracy (exponential convergence for analytic functions). – Geoffrey Irving Feb 08 '14 at 01:39
  • They are periodic within a certain range. Is taking the Fourier transform and then integrating the trigonometric polynomial really that efficient? I have to do this much more than 100,000 times, so efficiency matters at least a little bit. – Andrew Spott Feb 08 '14 at 02:01
  • @GeoffreyIrving: Sorry, they are on a non-uniform grid, which makes taking the fourier transform difficult. – Andrew Spott Feb 10 '14 at 22:36
  • @BillBarth: I'm sorry, I misunderstood you. f1 and f2 are functions of the form of a Coulomb Wave: 14.1.3 in Abramowitz and Stegun, or at least fairly close. – Andrew Spott Feb 10 '14 at 22:39
  • If you have the analytical form of the functions, is there a reason you have a particular grid that you want to integrate them on? It seems like an adaptive quadrature scheme ought to be able to integrate them nicely if you can choose the points arbitrarily. – Bill Barth Feb 10 '14 at 22:47
  • @BillBarth: I have the approximate analytical form, not so much the exact analytical form. These particular results can be written down exactly, however, I need this code to work for an extension that can't be written down exactly. So, I need to be able to compute this using the values that I have on the grid that I have. – Andrew Spott Feb 10 '14 at 23:30
  • Taking the Fourier transform is $O(n \log n)$ with a low constant and integrating the result is trivially $O(n)$, so it should be fairly efficient. I still think Fourier methods are likely the best option, but it's certainly harder on a strange grid. Using a logarithmic grid for a roughly constant frequency function is fairly strange; is the frequency varying accordingly? – Geoffrey Irving Feb 10 '14 at 23:58
  • @GeoffreyIrving: it's $O(n^2)$ for non-uniform grids, isn't it? Also, I'm using a logarithmic grid due to the potential, the large eigenvalues don't care as much, but the low eigenvalues due. It is easier to have all functions use the same grid (especially when I'm trying to do this numerical integration). – Andrew Spott Feb 11 '14 at 00:25
  • Possibly for arbitrary grids; I'm not sure if you can do better for a logarithmic grid. – Geoffrey Irving Feb 11 '14 at 00:26
  • @GeoffreyIrving: I'll have to look into that. – Andrew Spott Feb 11 '14 at 00:28

0 Answers0