# [Maxima] Integrating function with abs or max

sen1 at math.msu.edu sen1 at math.msu.edu
Tue Jan 30 23:33:14 CST 2007

> On 1/22/07, Ray Tice <trayracing at yahoo.com> wrote:
>
>> How do I reformulate functions that use abs or max so that maxima can
>> integrate them?

This is really a question of finding the zeroes of a function and
writing a sum of integrals.

For instance, take

integrate( max(f(x),g(x)),x) where

f and g are known,

Since the max is determined by where  f(x) - g(x) > 0 or < 0, one
simply has to compute the places where f(x) -g(x) = 0 and work on the
intervals between them individually.

Let h(x) = f(x) - g(x)

Suppose h(x) = 0 for finitely many points

x = a0 < a1 < a2 < . . . ak.

For simplicity, say there are only 3 points.

a < b < c

Pick d, e such that  a < d < b < e < c and compute

h(d), h(e)

If h(d) > 0, and h(e) < 0, then max(f,g) = f on (a,b) and g on
(b,c),
so the integral of max(f,g) is just

integrate(f(x),x,a,b) + integrate(g(x),x,b,c)

The other cases are similar.

This is easily handled for numerical integration.

For symbolic integration, it becomes a question of whether one can
find the roots of h(x) symbolically.

Incidentally, I tried some of these kinds of integrals in Mathematica
and Maple.

They do better than maxima at the present time (e.g. in integrating
abs(x) for instance) but they don't do much better on fairly  complicated
functions.

HTH.

-sen