MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Integrate[], Sort[] and Hold[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101012] Re: [mg100994] Integrate[], Sort[] and Hold[]
  • From: "David Park" <djmpark at comcast.net>
  • Date: Sat, 20 Jun 2009 04:03:04 -0400 (EDT)
  • References: <24964246.1245461320010.JavaMail.root@n11>

I was somewhat surprised that the following worked:

Integrate[Min[2^a, 3^a], {a, -1, 1}]
% // N
(2 Log[2] + Log[27])/(Log[2] Log[27])
2.04952

NIntegrate[Min[2^a, 3^a], {a, -1, 1}]
2.04952


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/ 



From: Neil Stewart [mailto: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: compress lists with mean for equal elements
  • Next by Date: Re: expression form
  • Previous by thread: Re: Integrate[], Sort[] and Hold[]
  • Next by thread: Re: Integrate[], Sort[] and Hold[]