> 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
===========================================
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
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
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