Minimizing a function scipy
<p>I got a function (error like) which I have to minimize and obtain new parameters alpha and r:</p>

<pre><code>#!/usr/bin/env python
import numpy as np
from scipy.integrate import quad
import scipy.optimize as opt

def integrand(t, alpha, r):
    return np.exp(-alpha*(t-r))**2

def my_function(alpha, r):
    return quad(integrand, 0, 5.0, args=(alpha, r))[0]

alpha = np.arange(1.0, 2.0, 0.1)
r = np.arange(1.0, 2.0, 0.1)
x0 = np.array([1.3, 0.7, 0.8, 1.9, 1.2])
res = opt.minimize(my_function, x0, args=(alpha, r), method='CG', tol=1.e-2, options={'gtol': 0.01, 'maxiter': 5})
</code></pre>

<p>My first question is if I picked up the right minimization method. If so could anybody elaborate what arguments I have to pass to the minimize method?</p>

<p>Currently the error message is returned:</p>

<pre><code>File "./test.py", line 15, in &lt;module&gt;
    res = opt.minimize(my_function, x0, args=(alpha, r), method='CG', tol=1.e-2, options={'gtol': 0.01, 'maxiter': 5})
  File "/usr/local/lib/python2.7/site-packages/scipy/optimize/_minimize.py", line 439, in minimize
    return _minimize_cg(fun, x0, args, jac, callback, **options)
  File "/usr/local/lib/python2.7/site-packages/scipy/optimize/optimize.py", line 1159, in _minimize_cg
    gfk = myfprime(x0)
  File "/usr/local/lib/python2.7/site-packages/scipy/optimize/optimize.py", line 289, in function_wrapper
    return function(*(wrapper_args + args))
  File "/usr/local/lib/python2.7/site-packages/scipy/optimize/optimize.py", line 622, in approx_fprime
    return _approx_fprime_helper(xk, f, epsilon, args=args)
  File "/usr/local/lib/python2.7/site-packages/scipy/optimize/optimize.py", line 556, in _approx_fprime_helper
    f0 = f(*((xk,) + args))
  File "/usr/local/lib/python2.7/site-packages/scipy/optimize/optimize.py", line 289, in function_wrapper
    return function(*(wrapper_args + args))
TypeError: my_function() takes exactly 2 arguments (3 given)
</code></pre>