Re: piecewice pdf, problems with cdf

*To*: mathgroup at smc.vnet.net*Subject*: [mg105378] Re: [mg105365] piecewice pdf, problems with cdf*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Mon, 30 Nov 2009 06:11:06 -0500 (EST)*Reply-to*: hanlonr at cox.net

pdf[x_] = Piecewise[{{x^2/9, 0 < x <= 3}}]; cdf[x_] = Assuming[{Element[x, Reals]}, Integrate[pdf[t], {t, -Infinity, x}]] Piecewise[{{1, x > 3}, {x^3/27, Inequality[0, Less, x, LessEqual, 3]}}] cdf[1] 1/27 Plot[{pdf[x], cdf[x]}, {x, -1, 4}, Frame -> True, Axes -> False] Bob Hanlon ---- michael partensky <partensky at gmail.com> wrote: ============= 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?