[Date Index]
[Thread Index]
[Author Index]
Re: Integrate[], Sort[] and Hold[]
*To*: mathgroup at smc.vnet.net
*Subject*: [mg101021] Re: [mg100994] Integrate[], Sort[] and Hold[]
*From*: DrMajorBob <btreat1 at austin.rr.com>
*Date*: Sun, 21 Jun 2009 07:05:10 -0400 (EDT)
*References*: <200906200047.UAA00917@smc.vnet.net>
*Reply-to*: drmajorbob at bigfoot.com
Try this:
Clear[f, g]
f[a_] := Min[2^a, 3^a]
g[a_] := Max[2^a, 3^a]
Integrate[{f@a, g@a}, {a, -1, 1}]
N@%
{(2 Log[2] + Log[27])/(Log[2] Log[27]), (Log[3] + 2 Log[4])/(
Log[3] Log[4])}
{2.04952, 2.54183}
NIntegrate[{f@a, g@a}, {a, -1, 1}]
{2.04952, 2.54183}
Bobby
On Fri, 19 Jun 2009 19:47:57 -0500, Neil Stewart
<neil.stewart at warwick.ac.uk> wrote:
> 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.
>
>
>
>
>
--
DrMajorBob at bigfoot.com
Prev by Date:
**Re: TeX output via TeXForm: variable name translation**
Next by Date:
**Looping- Programming**
Previous by thread:
**Integrate[], Sort[] and Hold[]**
Next by thread:
**Re: Integrate[], Sort[] and Hold[]**
| |