Python changing function definition in loop?
<p>I was wondering if it is possible to do the following: If a function takes a function as argument, can I make it so that the argument of the inner function can be changed in a loop?</p>

<p>I have a function that takes any function f and integrates it over a, b. The problem is if I in a loop want to integrate cos(1* x) and then cos(2*x) ....cos(N*x) I don't know how to make my first function understand that when I say integrate(f(i),a,b) I don't mean integrate cos(1) or cos(2) BUT cos(1*x) or cos(2*x) and so on.</p>

<p>Eg:</p>

<pre><code>def integrate(f,a,b):
 h = float(b-a)/10;
 I = 0;
 for i in range(10):
   I+= f(h*i);   &lt;----(1)
return I;

A = zeros(N);
for k in range(N):
  A[k] = integrate(cos(k), a,b)   &lt;-----(2)
</code></pre>

<p>What I want is for cos(k) in (2) to be called such that in (1) it becomes f(k * h * i), does this make sense to you? I want to change the parameter of (1) by changing (2). I need this for a fourier series function I am doing. The way it currently works is that instead of calling cos() with (k * h* i) inside the paranthesis it will just call cos(k).</p>
