[Date Index]
[Thread Index]
[Author Index]
Integrate[], Sort[] and Hold[]
*To*: mathgroup at smc.vnet.net
*Subject*: [mg100994] Integrate[], Sort[] and Hold[]
*From*: Neil Stewart <neil.stewart at warwick.ac.uk>
*Date*: Fri, 19 Jun 2009 20:47:57 -0400 (EDT)
*Reply-to*: Neil Stewart <neil.stewart at warwick.ac.uk>
I am having trouble integrating a function which contains Sort[]. Here is a
stripped down (if slightly odd) example:
In = Integrate[Sort[{2, 3}^a], {a, -1, 1}]
Out = {3/Log[4], 8/Log[27]}
Mathematica is evaluating this as follows. First, Sort[{2, 3}^a] is
evaluated as {2^a, 3^a}. Then Integrate[2^a, {a, -1, 1}] gives the first
term 3/Log[4]. Finally Integrate[3^a, {a, -1, 1}] gives the second term
8/Log[27]. Note here that Sort[] is sorting 2^a and 3^a without knowing the
value of a. That is, sort is sorting the raw symbolic expressions.
I would prefer Sort[] to wait until it knows the value of a before sorting.
For example, when a is -1, then 2^a = 1/2 and 3^a = 1/3, so Sort[{2, 3}^a]
would be {1/3, 1/2}. However when a is 1, then 2^a = 2 and 3^a = 3, so
Sort[{2, 3}^a] would be {2, 3}. That is, in the first case the terms are
swapped, but in the second case they are not. So what I'm after is
In = Integrate[Sort[{2, 3}^a], {a, -1, 1}]
Out = {2/Log[3] + 1/Log[4], 1/Log[2] + 2/Log[27]}
(* This does not actually happen *)
[If you prefer to picture this, Plot[{2^a, 3^a}, {a, -1, 1}] draws two
increasing lines that cross at a = 0. Mathematica is integrating under each
curve. I'm trying to integrate under the line made from the two lower
segments, and under the line made from the two upper segments.]
I've tried using Hold[], ReleaseHold[], and Evaluate[] but have got myself
into a terrible mess. Obviously with this trivial example I could just split
the integral up myself, but is there a way to achieve delaying Sort[] until
a is known? I would be very grateful for any comments.
Prev by Date:
**Re: Text and multiple calculations in an IF condition**
Next by Date:
**Re: SphericalHarmonics strange behavior**
Previous by thread:
**Re: TeX output via TeXForm: variable name translation**
Next by thread:
**Re: Integrate[], Sort[] and Hold[]**
| |