MathGroup Archive 2003

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

Search the Archive

Re: Integrate with piecewise function


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


  • Prev by Date: Re: Integrate with piecewise function
  • Next by Date: Re: Re: recode procedural algorithm to faster functional module
  • Previous by thread: Re: Integrate with piecewise function
  • Next by thread: Re: Integrate with piecewise function