## Tuesday, January 3, 2012

### Mathematica Integral Fun

Consider the evaluation of the integral of 1/r between -1 and 1, in Mathematica.
• The function f(r) = 1/r has a discontinuity at r = 0.
• The indefinite integral of 1/r is simply log(r), which is real for positive "r", and is complex for -ve "r", and goes to negative infinity as r approaches zero.
• One might be tempted to think that getting definite integrals is easy if one knows the indefinite integral
• Not so fast. Discontinuties can complicate things!

Let us go back to the integral of f(r) between -1 and 1. From the symmetry of the figure it may be apparent that f(r) is an odd function, and the area under the curve (or the integral) should go to zero.

If we try to use Mathematica to integrate it with Integrate[f,{r,-1,1}], it complains that the integral does not converge.

We say, hmmm. Why don't we simply try to substitute the limits in the indefinite integral:
The answer makes sense since Log[1] = 0, and Log[-1] = i * pi, but is clearly not the correct answer?

The reason for this is that the First Fundamental Theorem of Calculus requires the antiderivative to be continuous over the range of integration, and from the second plot above, it is clear that this condition is violated.
So how do we figure this thing out? We could isolate the discontinuity by integrating close to zero (using "epsilon"), and perhaps take the limit later.

This gives the expected answer of zero.