[Date Index]
[Thread Index]
[Author Index]
Integration and Summation of Piecewise Functions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg52704] Integration and Summation of Piecewise Functions
*From*: ab_def at prontomail.com (Maxim)
*Date*: Thu, 9 Dec 2004 20:23:41 -0500 (EST)
*Sender*: owner-wri-mathgroup at wolfram.com
The Integration and Summation of Piecewise Functions module at
http://library.wolfram.com/infocenter/MathSource/5117/
has been updated; it can now handle examples like the following:
In[1]:=
<<piecewise`
PiecewiseIntegrate[Mod[E^-x, E^-(2*x)], {x, 0, Infinity}]
Out[2]=
(12 - Pi^2)/12
In[3]:=
PiecewiseIntegrate[DiracDelta''[x*Cos[x]], {x, -Infinity, Infinity}]
Out[3]=
(3*Pi^5 + 14*Pi^2*Zeta[3] + 744*Zeta[5])/Pi^5
In[4]:=
PiecewiseIntegrate[Max[Sin[a*x], 0], {x, 0, Pi}]
Out[4]=
If[a == -2, 1, 0] + If[a == 1, 2, 0] +
If[-2 < a < -1, (-1 - Cos[a*Pi])/a, 0] +
If[0 < a < 1, (1 - Cos[a*Pi])/a, 0] +
If[1 < a, (1 + Ceiling[a/2] + Cos[a*Pi] -
Ceiling[a/2]*Cos[a*Pi] + Floor[-(1/2) + a/2] +
Cos[a*Pi]*Floor[-(1/2) + a/2])/a, 0] +
If[a < -2, (-Ceiling[-(1/2) - a/2] -
Ceiling[-(1/2) - a/2]*Cos[a*Pi] - Floor[-(a/2)] +
Cos[a*Pi]*Floor[-(a/2)])/a, 0]
In[5]:=
PiecewiseSum[DiscreteDelta[i + j - k],
{i, -n, n}, {j, -n, n}, {k, -n, n},
Assumptions -> Element[n, Integers]]
Out[5]=
If[n == 0, 1, 0] + If[n == 1, 4, 0] +
If[0 < n, 1 + 2*n, 0] + If[1 < n, n + 3*n^2, 0]
It doesn't use the new features of Mathematica 5.1 and will work in
version 5.0 as well as 5.1. Mathematica 5.1 often gets such integrals
and sums wrong:
In[6]:=
Integrate[Max[x, a - x], {x, 0, a}]
Out[6]=
a^2/2
This is incorrect for all values of a other than 0; the correct answer
is If[0 < a, (3*a^2)/4, 0] + If[a < 0, a^2/4, 0].
In[7]:=
Assuming[x > 1,
Integrate[UnitStep[t1 - t2, 1 - t1 + t2, t2, 1 - t2],
{t1, -Infinity, x}, {t2, -Infinity, Infinity}]]
Out[7]=
Piecewise[{{1/2, x > 2}}, (-3 + 4*x - x^2)/2]
This is incorrect for all x>1; the correct answer under the given
assumptions is If[x < 2, (-2 + 4*x - x^2)/2, 0] + If[2 <= x, 1, 0].
Thus, even though the enhanced support for piecewise functions is
advertised as one of the main new features of Mathematica 5.1, there
doesn't seem to be any significant improvement in the integration of
piecewise functions: it still works relatively well only if you supply
'nice' conditions on the parameters, such that the answer doesn't
contain piecewise expressions. For example, if you make a lucky guess
and evaluate the last integral separately for 1<x<2 and x>2, then
you'll obtain the correct result.
The situation with piecewise sums seems even worse:
In[8]:=
Sum[UnitStep[k - k^2], {k, Infinity}]
Sum[UnitStep[k^2 - k], {k, Infinity}]
Out[8]=
Infinity
Out[9]=
Floor[K$3290^2]*UnitStep[-1 + K$3287^2]
The correct answers are, of course, 1 and Infinity respectively, and
certainly not something containing free variables.
In[10]:=
Sum[Floor[k], {k, n}]
Out[10]=
0
The answer should be identical to the result of Sum[k, {k, n}]. Worse
yet, Sum[Floor[k]^2, {k, n}] seems to go into infinite loop: it
generates $RecursionLimit::reclim warnings and gives a meaningless
output.
Another issue is that the decomposition given by Reduce is not always
disjoint (this is mentioned in the documentation). This means that if
you want to use Reduce to perform the decomposition of the
integration/summation range, it will lead to incorrect results because
some points will be counted more than once. For example:
In[11]:=
Reduce[(k != 0 || n != 0) && 0 <= k <= n && Element[k, Integers]]
Out[11]=
(k \[Element] Integers && n > 0 && 0 < k <= n) ||
(k \[Element] Integers && n > 0 && 0 <= k <= n)
The first Or clause describes a subset of the set described by the
second clause. This doesn't make much difference if the Reduce output
is to be used by functions like Minimize (except slowing things down,
since we'll be searching for extrema in the same region twice), but
such a decomposition is useless for the purpose of finding piecewise
integrals/sums.
Maxim Rytin
m.r at inbox.ru
Prev by Date:
**Re: Re: Re: Re: Finding the Fourier transform of discrete functions**
Next by Date:
**Re: Re: Re: A problem of numerical precision**
Previous by thread:
**Re: Re: problem getting the area under a parmetric curve**
Next by thread:
**Matrix m x n**
| |