Are user defined functions callable?
<p>I am not a very experience programmer. Please can you tell me why this code gives me the error message:</p>

<p>error: quad: first argument is not callable</p>

<p>code:</p>

<pre><code>from matplotlib import pyplot as plt
import numpy as np
import scipy.integrate as integrate

def parabola(x, a):
    return a+x**2

x=np.arange(-10, 10, 1)

plt.plot(x, parabola(x,2))

plt.show()

int1=integrate.quad(parabola(x,2), -5, 5)
print int1
</code></pre>

<p>Should all user defined functions be callable? </p>

<p>There are two problems in your code:</p>

<p>1) you call the function <code>parabola()</code>. Instead, pass it as an argument to <code>integrate</code>.</p>

<p>2) <code>parabola()</code> is a two argument function. <code>integrate</code> expects a single-argument function.</p>

<p>To solve the second problem, you need to convert the two-argument function to a single-argument function. This is a general technique known as <em>partial application</em> of functions.</p>

<p>Try this:</p>

<pre><code>def parabola1(x): return parabola(x, 2)

int1 = integrate.quad(parabola1, -5, 5)
print int1
</code></pre>

python numpy