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

*To*: mathgroup at smc.vnet.net*Subject*: [mg101192] Re: [mg100994] Integrate[], Sort[] and Hold[]*From*: Neil Stewart <neil.stewart at warwick.ac.uk>*Date*: Fri, 26 Jun 2009 06:51:28 -0400 (EDT)*Reply-to*: Neil Stewart <neil.stewart at warwick.ac.uk>

David and Bob, thanks for your suggestions. I need this to work with lists of more than two things. I support I could use Min and Max to make a new Sort function, but wondered if there might be a better way. So does anyone have any ideas why Min[] and Max[] behave differently to Sort[]? I wondered if it ws about attributes. Attributes[Sort] = {Protected} Attributes[Min] = {Flat, NumericFunction, OneIdentity, Orderless, Protected} Attributes[Max] = {Flat, NumericFunction, OneIdentity, Orderless, Protected} But setting the attributes of Sort[] to match Min[] or Max[] doesn't change Sort[]'s behaviour in Integrate[]. All comments very welcome. On Fri, 19 Jun 2009, David Park wrote: > 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. > > > > > >

**Eigenvalue bug in Mathematica 7.0.0**

**Re: Wolfram | Alpha: Acres per square mile? (oddities)**

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

**extract coefficients**