RE: Sheer frustration with integration of piecewise continuous functions
- To: mathgroup at smc.vnet.net
- Subject: [mg40910] RE: [mg40907] Sheer frustration with integration of piecewise continuous functions
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Thu, 24 Apr 2003 05:24:17 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: Madhusudan Singh [mailto:spammers-go-here at yahoo.com] To: mathgroup at smc.vnet.net >Sent: Wednesday, April 23, 2003 11:18 AM >To: mathgroup at smc.vnet.net >Subject: [mg40910] [mg40907] Sheer frustration with integration of piecewise >continuous functions > > >Clear["'*"]; >(*ClearAttributes[Which, HoldAll];*) > >f[x_, L_, fpeak_] := (fpeak /L) Which[((0 <= x) && (x < 0.6 >L)), x/(0.6 >),((0.6 L <= x) && (x <= 0.9 L)), L, ((0.9 L < x) && (x <= L)) , 10 (L >-x)]; >Plot[f[x, 1, 1], {x, 0, 1}]; >Print[Integrate[f[x, L, fpeak], {x, 0, L}, Assumptions -> {L >>= 0, fpeak >= >0, x >= 0, x <= L}]]; > >I have struggled with the above integration (believe me, its >just a test case, I have a much more complicated function) for >an hour now. > >What is missing above ? The plot evaluates but the integral >does not. Why does Mathematica make it so damned difficult to >work with piecewise continuous functions ? > Madshusudan, to integrate a function it must be part of the calculus defined, i.e. there must be rules defined. As you may conceive this is a bit hard to do for general procedural expressions containing Which, If, Condition etc. However DiracDelta, UnitStep,... are part of that calculus. Such this works: In[31]:= f2[x_, L_, fpeak_] := fpeak/L (x 10/6 UnitStep[x] + (L - x 10/6)UnitStep[x - 6/10 L] + (10 (L - x) - L) UnitStep[x - 9/10 L] - 10 (L - x)UnitStep[x - L]) In[32]:= Plot[f2[x, 2, 1], {x, 0, 2}]; In[34]:= Integrate[f2[x, L, fpeak], {x, 0, L}, Assumptions -> {L > 0}] Out[34]= (-(1/60))*fpeak*L*(3*UnitStep[L/10] + 8*UnitStep[(2*L)/5] - 50*UnitStep[L]) In[35]:= % /. {UnitStep[a_. L] /; a > 0 -> 1, UnitStep[a_. L] -> 0} Out[35]= (13*fpeak*L)/20 This is the same as done by hand: In[36]:= fpeak L (6/10 *1/2 + 3/10 + 1/10*1/2) Out[36]= (13*fpeak*L)/20 -- Hartmut Wolf