Re: piecewice pdf, problems with cdf

*To*: mathgroup at smc.vnet.net*Subject*: [mg105379] Re: piecewice pdf, problems with cdf*From*: "Nasser M. Abbasi" <nma at 12000.org>*Date*: Mon, 30 Nov 2009 06:11:18 -0500 (EST)*References*: <hetheh$fvu$1@smc.vnet.net>

To do calculus with piecewise functions, always use Piecewise[]: In[24]:= f1[x_] := Piecewise[{ {(1/9)*x^2 , 0 < x <= 3}, {0, True} }]; cdf[x_] := Integrate[f1[v], {v, -Infinity, x}]; Out[26]= 1/27 --Nasser "michael partensky" <partensky at gmail.com> wrote in message news:hetheh$fvu$1 at smc.vnet.net... > Hi! Teaching the continuous distributions, I needed to introduce the > piecewise functions. > Here is the example that did not work well: > > In[56]:= f1[x_] /; 0 < x <= 3 := 1/9 x ^2; > f1[x_] := 0; > > Plot[f1[x],{x,-1,4}] works fine. However, the results for cdf are > ambiguous > In[57]:= cdf[x_] := Integrate[f1[v], {v, -\[Infinity], x}] > > In[59]:= cdf[1] > Out[59]= 0 > > I thought that may be the second definition (for some reason) overwrote > the > first, but apparently this was not the case. > > Then I tried using Which, > > f1[x_] := Which[0 < x <= 3, x^2/9, x <= 0 || x > 3, 0]; > > Plot[f2[x], {x, -1, 4}] worked fine. > > However, Plotting CDF is very slow. > > What is the reason for the first error and how to accelerate (compile?) > the > second? > > Thanks > Michael > > PS: I was aware about the issues with the derivatives of Piecewise > functions, but expected integration to be safe. What did i do wrong? >