RE: Integration of very simple partwise defined functions fails
- To: mathgroup at smc.vnet.net
- Subject: [mg15775] RE: [mg15720] Integration of very simple partwise defined functions fails
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Sun, 7 Feb 1999 02:03:53 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
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