Re: Integrate with piecewise function
- To: mathgroup at smc.vnet.net
- Subject: [mg44070] Re: [mg44052] Integrate with piecewise function
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Tue, 21 Oct 2003 02:07:43 -0400 (EDT)
- References: <200310190510.BAA08054@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Chia-Ming wrote:
>
> Excuse me,
>
> I define a function describing the distance on the edge of a circle.
>
> dis[x_, xi_] := Which[ x - xi >= 0, x - xi, x - xi < 0, xi - x]
>
> Then I find that the command Integrate does not yield the result (37/72).
>
> Integrate[dis[x, 0], {x, 0, 1/6}]
>
> If I use the command NIntegrate, only the numerical result is yielded. But I
> want the
> exact result.
>
> NIntegrate[dis[x, 0], {x, 0, 1/6}]
> 0.513891
>
> How can I get the exact result, just like I keyin the command by hand.
>
> Integrate[-x, {x, -1, 0}] + Integrate[x-0, {x, 0, 1/6}]
> 37/72
>
> Thank you very much for your help!
>
> cmyu
One method is to use the Calculus`Integrate standard add-on package.
In[1]:= dis[x_, xi_] := Which[ x - xi >= 0, x - xi, x - xi < 0, xi - x]
In[2]:= Integrate[dis[x, 0], {x, -1, 1/6}]
1
Out[2]= Integrate[Which[x >= 0, x - 0, x - 0 < 0, 0 - x], {x, -1, -}]
6
In[3]:= <<Calculus`Integration`
In[4]:= Integrate[dis[x, 0], {x, -1, 1/6}]
37
Out[4]= --
72
Other approaches, already mentioned in this thread, include rewriting
the function in terms of Abs or UnitStep.
Daniel Lichtblau
Wolfram Research