MathGroup Archive 1999

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

Search the Archive

RE: Integration of very simple partwise defined functions fails


Daniel Oberfeld  wrote:
___________________

I was quite surprised that Mathematica will not evaluate any Integrals
of simple functions like 

f[x_/;x<=2]:=1
f[x_/;x>2]:=2

Integrate[f[x],{x,0,1}]

NIntegrate also complains about singularities.

Do I miss something? There must be a fast way out...

________________

I don't know what you can do to get Integrate to deal with this.   But
NIntegrate[f,{x,x0,x1,x2,...xi,xj}]effectively breaks up the integral
into 
pieces along [x0,x1], [x1,x2], ...,[x,xi].  So include the point of 
discontinuity in the range of integration.

In[8]:=
NIntegrate[f[x],{x,0,2,5}]
Out[8]=
8.


If you don't know where the discontinuities are you can write some code
that does it by using NDSolve on the equivalent Diff. Eq.

In[9]:=
NIntegrate2[f_,{x_,a_,b_}]:=
 Module[{y},
   y[b]/.NDSolve[{y'[x]==f,y[a]==0},y,{x,a,b}][[1]]
 ]


In[10]:=
NIntegrate2[f[x],{x,0,5}]
Out[10]=
8.00001


Regards,
Ted Ersek


  • Prev by Date: Re: Re: 4th order DE, NDSolve no solution, why?
  • Next by Date: RE: BracketingBar for output
  • Previous by thread: NDSolve problem
  • Next by thread: log plots