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:

$$\frac{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

-
Re the question title: As far as I know, quadrature is (a somewhat oldfashioned term for) integration. –  Harald Hanche-Olsen Feb 22 '12 at 15:44
Nowadays, I know that in numerical analysis the term 'quadrature' is used to refer to integration rules based on interpolating polynomials. I this case, you may as well use the elementary anti-derivative. en.wikipedia.org/wiki/… –  dls Feb 22 '12 at 16:30

THE CORRECT ANSWER FOR CORRECT QUESTION IS

$$\int_a^{b} \frac{x}{d^2} - x^{2}$$

$$= \left( \frac{x^2}{2d^2} - \frac{x^3}{3} \right)$$

$$= x^2 \left( \frac{1}{2d^{2}} - \frac{x}{3} \right)$$

$$= \frac{x^2}{6d^2} (3-2d^{2}x)$$

Now apply the limits from a to b

$$= \frac{1}{2d^2}(b^2-a^2) - \frac{1}{3}(b^3-a^3)$$

To simplify further

$$= (b-a) \left( \frac{(a+b)}{2d^2} - \frac{(b^2+ab-a^2)}{3} \right)$$

If you are writing a program then

$$= \frac{(b^2-a^2)}{2d^2} - (b-a)\frac{b^2+ab-a^2}{3}$$ would be better because the second expression (with a 3 in the bottom) is only evaluated once

-
It may (or may not) be worth pointing out that the expression x/(d^2)-(x^2) in Python is equivalent to the function $(x/d^2) - x^2$, rather than $x/(d^2-x^2)$. –  Chris Taylor Feb 22 '12 at 13:33
@Chris I edited your question. Next time, try to clearly write the equation in $\LaTeX$ –  Pedro Tamaroff Feb 22 '12 at 14:26
@Peter (i) I don't think you meant to address that to me, and (ii) you don't know whether the OP means $x/d^2-x^2$ or $x/(d^2-x^2)$, so your edit may have changed the meaning of the question. –  Chris Taylor Feb 22 '12 at 14:36
Peter, thanks for putting it into latex but the questions was for x/(d^2−x^2). cheers –  Karim Sutton Feb 22 '12 at 14:46
@ChrisTaylor I was suspecting that. But I don't know why I thought you were the OP! Sorry! –  Pedro Tamaroff Feb 22 '12 at 14:54