Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

(Newbie) More confusion with integral of absolute vals

65 views
Skip to first unread message

L. Dwynn Lafleur

unread,
Nov 1, 1997, 3:00:00 AM11/1/97
to

Suppose I want to integrate the absolute value of x over the range a->b.
It's simple enough in Maple V Release 4:

> ii:=int(abs(x),x=a..b);

2 2
ii := 1/2 b signum(b) - 1/2 a signum(a)

> assume(0<a,a<b);
> ii;

2 2
1/2 b~ - 1/2 a~

where the tildes (~) indicate there are assumed properties for a and b.

If I try the same thing in Mathematica 3.01, I get

In[1]:= ii=Integrate[Abs[x],{x,a,b}] Out[1]= $Aborted

In other words, Mathematica cannot perform the integral and I must abort
the evaluation. Even if I try to place Assumptions in the Integrate
function, the integration is not performed. What am I missing here?
Can't the integration be performed as easily in Mathematica as it is in
Maple?

--

=========================================== L. Dwynn Lafleur
Professor of Physics
The University of Southwestern Louisiana Lafayette, Louisiana (USA)
laf...@usl.edu
===========================================

David Withoff

unread,
Nov 2, 1997, 3:00:00 AM11/2/97
to

If you replace Abs[x] by Sqrt[x^2] then Mathematica will do the
integral:

In[1]:= Integrate[Sqrt[x^2], {x, a, b}]

2 2
-(a Sqrt[a ]) b Sqrt[b ]
Out[1]= ------------- + ----------
2 2

or you can add a rule to Integrate that will cause this to be done
automatically. The behavior of Integrate[Abs[x],{x,a,b}] in
Mathematica Version 3.0 is something that needs to be fixed, and this
is one way to fix it.

Lurking beneath this seemingly simple integral is some rather awkward
trickery, in Maple and essentially everywhere else. For example, the
following result from Maple V Release 4

> int(abs(sin(x)), x=a..b);
-cos(b) signum(sin(b)) + cos(a) signum(sin(a))

is wrong for all but a narrow range of relationships between the
parameters a and b. There are no general algorithms for integrating
the absolute value function, so it is likely that there are lots of
errors like this. Given all of the work that needs to done I am more
than willing to excuse this sort of thing, and am in fact quite
impressed that integration algorithms can get the right answer for
things like this:

In[5]:= Integrate[Abs[Sin[x]], {x, 0, 20}]

Out[5]= 13 - Cos[20]

I want to stop short of describing integration of absolute value as
hopeless, since problems such as these certainly can in principle be
fixed, but this is a difficult and largely unsolved problem, and the
fact that Maple and Mathematica have various difficulties integrating
absolute value is not at all surprising. It is a good idea to check
the results for integrals involving functions like absolute value no
matter what system you use, and where possible an even better idea is
to somehow rearrange the input (such as by using Sqrt[x^2] in place of
Abs[x]) so that these problems don't come up in the first place.

Dave Withoff
Wolfram Research


jmthomas

unread,
Nov 2, 1997, 3:00:00 AM11/2/97
to

Your question has been rather disappointing me and I'm not sure my
answer can help you in any way:
I tried Integrate[Abs[x],{x,a,b}] and, as you did, had to abort the
evaluation after some ten minutes.
I must admit that, if Mathematica cannot answer properly, it should at
least answer quickly. I tried to submit your integral to "The
integrator" on Wolfram Research site, the answer was: Mathematica was
not able to do the integral you requested. If you think the integral
can in fact be done, please send mail to webm...@integrals.com so
it can be analyzed by our mathematical development group.
Beside the fact "the integrator" performs indefinite integrals only, I
leave you submit your case to them.

Anyway, this could help:
As far as Abs is a general function for real AND complex numbers, it
certainly dizzles the kernel. So I wrote:
absoluteValue[x_]:=If[x>=0,x,-x] which defines Abs[x] for real
only. And then f[a_,b_]:=Integrate[absoluteValue[x],{x,a,b}] Please
notice the fact that this definition is a delayed definition. Then,
giving values to a and b returns a correct numerical result, which
might be what you are looking for.
Hope this helps.

----------------------------------------------- Jean-Marie THOMAS
Conseil et Audit en Ingnierie de Calcul jmth...@cybercable.tm.fr
www.cybercable.tm.fr/~jmthomas

-----Message d'origine-----
De: L. Dwynn Lafleur [SMTP:laf...@usl.edu] Date: samedi 1 novembre 1997
09:34
0: math...@smc.vnet.net
Objet: [mg9367] (Newbie) More confusion with integral of absolute vals

Suppose I want to integrate the absolute value of x over the range a->b.
It's simple enough in Maple V Release 4:

> ii:=int(abs(x),x=a..b);

2 2
ii := 1/2 b signum(b) - 1/2 a signum(a)

> assume(0<a,a<b);
> ii;

2 2
1/2 b~ - 1/2 a~

where the tildes (~) indicate there are assumed properties for a and b.

If I try the same thing in Mathematica 3.01, I get

In[1]:= ii=Integrate[Abs[x],{x,a,b}] Out[1]= $Aborted

In other words, Mathematica cannot perform the integral and I must abort
the evaluation. Even if I try to place Assumptions in the Integrate
function, the integration is not performed. What am I missing here?
Can't the integration be performed as easily in Mathematica as it is in
Maple?

--

L. Dwynn Lafleur


Professor of Physics
The University of Southwestern Louisiana Lafayette, Louisiana (USA)

laf...@usl.edu =20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


Pedro A Santos

unread,
Nov 5, 1997, 3:00:00 AM11/5/97
to

David Withoff wrote:
>
> I want to stop short of describing integration of absolute value as
> hopeless, since problems such as these certainly can in principle be
> fixed, but this is a difficult and largely unsolved problem, and the
> fact that Maple and Mathematica have various difficulties integrating
> absolute value is not at all surprising. It is a good idea to check
> the results for integrals involving functions like absolute value no
> matter what system you use, and where possible an even better idea is
> to somehow rearrange the input (such as by using Sqrt[x^2] in place of
> Abs[x]) so that these problems don't come up in the first place.

Unfortunately, I've found more of these type of problems with Integrate,
when trying to use Mathematica with step or piecewise continuous
functions. For instance, Mathematica can't give the primitive

Integrate[If[0<x<1,1,0],x].

The kind of rearrangements you sugest (in the above case, for instance
writing UnitStep[x]-UnitStep[x-1] instead of If[0<x<1,1,0]) can be
dangerous because

1- Usually the expressions are not completly equivalent (Sqrt[x^2] is
equal to Abs[x] only for real numbers).

2- Even if they are, some expressions when used in the internal
algoritms of Mathematica can lead to other types of problems (UnitStep
is a function with unbounded domain and infinite integral, for
example).

As it is, Mathematica has three different ways to represent piecewise
continuous functions (Conditionals, UnitStep, Signal), but the internal
treatment is different. This leads to varying responses by the same
commands (Integrate, FourierTransform, etc) to what is mathematically
equivalent, and is very anoying when I am trying to work with
Mathematica. Is there a solution for this problem?


Pedro Santos


0 new messages