Integrating abs(x)?



Alasdair McAndrew wrote:
> Thanks for your replies.  What I really want to do is calculate the 
> total variation of some functions f; this being defined as the integral 
> of the absolute value of the derivative of f (see 
> http://en.wikipedia.org/wiki/Total_variation).  The integral of abs was 
> just a test case.
> 
> I can probably use pmint, but the results it produces aren't really 
> useful.  For example:
> 
> (%i1) pmint(abs(sin(x)),x);
> (%o1) -cos(x)*abs(sin(x))/sin(x)
> 
> which is true, but doesn't allow me to enter values for which sin(x)=0.  
> This is too restrictive.
> 
> I could probably do all this numerically, but I would rather obtain 
> closed-form solutions than numerical approximations.
> 
> I'll keep fiddling.

Here's one possible way, which is how I would probably do it by hand, 
for the total variation problem.

Find all the points where f'(x) = 0.  Maxima can do this for some 
functions, but not all.   Let the roots be called x[n].  Then the 
integral you want becomes the sum of integrals of the form

abs(integrate(f'(x),x, x[n],x[n+1))

Maxima might be able to compute this definite integral.

Hope I didn't make any mistakes!

Ray