user1171835 - 1 year ago 94

Python Question

I have been having a few issues using the quadrature function in python 2.7 (part of the scipy.integrate module). The equation I am trying to integrate is simply:

`x/(d^2)-(x^2)`

The integration is between limits a and b. However, I need to do the integration at 40 different values of d and am not sure how to pass in the second argument so as to loop the integration over the values of d. Any help would be much appreciated and is quadrature the best way to evaluate this problem.

Thanks

Answer Source

```
In [9]: from scipy.integrate import quad
In [10]: a = 0
In [11]: b = 1
In [12]: [quad(lambda x, d: x/(d**2)-x**2, a, b, args=d) for d in range(2, 5)]
Out[12]:
[(-0.20833333333333334, 2.3717550132075781e-15),
(-0.27777777777777773, 3.0886887822595405e-15),
(-0.30208333333333337, 3.3546344203581545e-15)]
```

Change the `for d in range(2, 5)`

as required.