title: Integrating an oscillating (interpolated) function with GSL and python
body: <p>I am trying to integrate a highly oscillatory data with the function <em>qawo</em> from the <a href="http://www.gnu.org/software/gsl/" rel="nofollow">GSL Scientific Library</a> and <a href="http://pygsl.sourceforge.net/" rel="nofollow">pygsl</a> in python. Since I am dealing with data I though that a interpolated function could work, but GSL gives me an incorrect result <strong>!!</strong>. Let me explain by taking the function <strong>Sin(x)/(1+x²)</strong> as an example.</p>
  
  <p>The following code works fine:</p>
  
  <pre><code>import pygsl
  from  pygsl import integrate
  
  def f1(x,y):
      return 1./(1 + x**2)
  sys = integrate.gsl_function(f1, None)
  
  w = integrate.workspace(100)
  cyclew = integrate.workspace(1000000)
  
  table = integrate.qawo_table(1, 10000, integrate.SINE, 100)
  flag, result, error = integrate.qawo(sys, 0, 1e-8, 1e-8, 100, w, table)
  </code></pre>
  
  <p>gives <strong>0.626761</strong> as it should. But if we simulated data points using the above function...</p>
  
  <pre><code>xarr = np.linspace(0,1e15,1e30)  
  yarr = np.sin(xarr)/(1.+xarr**2)
  
  interp = interpol.interp1d(xarr,yarr)
  
  def fgsl(x,y):
      return interp(x)
  
  syst = integrate.gsl_function(fgsl, None)
  
  w = integrate.workspace(1000)
  cyclew = integrate.workspace(100000000)
  
  table = integrate.qawo_table(1, 1e10, integrate.SINE, 100)
  
  flag, result, error = integrate.qawo(syst, 0, 1e-15, 1e-15, 100, w, table)
  </code></pre>
  
  <p>which gives a completely wrong result: <strong>4.2426e-21</strong></p>
  
  <p>Moreover, if we integrated <em>yarr</em> with the <em>simps</em> function:</p>
  
  <pre><code>import scipy.integrate as ints
  res = ints.simps(yarr,xarr)
  </code></pre>
  
  <p>gives a pretty good approximation: <strong>0.64676099</strong>.</p>
  
  <p>Just assume that I can't use the Simpson's rule. Does anyone knows how can I use an interpolation function with gsl? or how can I change the code in order to do the integration?</p>
  
  <p>Thanks in advance.</p>