title: Gauss(-Legendre) quadrature in python
body: <p>I'm trying to use Gaussian quadrature to approximate the integral of a function.  (More info here: <a href="http://austingwalters.com/gaussian-quadrature/" rel="nofollow">http://austingwalters.com/gaussian-quadrature/</a>).  The first function is on the interval [-1,1].  The second function is generalized to [a,b] by change of variable.  The problem is that I keep getting the error "'numpy.ndarray' object is not callable".  I assume (please correct me if I'm wrong) this means I've tried to call the arrays w and x as functions, but I'm not sure how to fix this.</p>
  
  <p>This is the code</p>
  
  
  
  <pre><code>from __future__ import division
  from pylab import *
  from scipy.special.orthogonal import p_roots
  
  def gauss1(f,n):
      [x,w] = p_roots(n+1)
      f = (1-x**2)**0.5
      for i in range(n+1):
          G = sum(w[i]*f(x[i]))
      return G
  
  def gauss(f,a,b,n):
      [x,w] = p_roots(n+1)
      f = (1-x**2)**0.5
      for i in range(n+1):
          G = 0.5*(b-a)*sum(w[i]*f(0.5*(b-a)*x[i]+ 0.5*(b+a)))
      return G
  </code></pre>
  
  
  
  <p>These are the respective error messages</p>
  
  
  
  <pre><code>gauss1(f,4)
  Traceback (most recent call last):
  
    File "&lt;ipython-input-82-43c8ecf7334a&gt;", line 1, in &lt;module&gt;
      gauss1(f,4)
  
    File "C:/Users/Me/Desktop/hw8.py", line 16, in gauss1
      G = sum(w[i]*f(x[i]))
  
  TypeError: 'numpy.ndarray' object is not callable
  
  gauss(f,0,1,4)
  Traceback (most recent call last):
  
    File "&lt;ipython-input-83-5603d51e9206&gt;", line 1, in &lt;module&gt;
      gauss(f,0,1,4)
  
    File "C:/Users/Me/Desktop/hw8.py", line 23, in gauss
      G = 0.5*(b-a)*sum(w[i]*f(0.5*(b-a)*x[i]+ 0.5*(b+a)))
  
  TypeError: 'numpy.ndarray' object is not callable
  </code></pre>