MathGroup Archive 2009

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

Search the Archive

Re: Re: piecewice pdf, problems with cdf

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105477] Re: [mg105449] Re: piecewice pdf, problems with cdf
  • From: michael partensky <partensky at gmail.com>
  • Date: Fri, 4 Dec 2009 04:33:06 -0500 (EST)
  • References: <hetheh$fvu$1@smc.vnet.net> <200912031114.GAA01088@smc.vnet.net>

Thanks, Nasser.
The issue is resolved.
Some additional advises you can find in other responses.
Especially helpful was substituting ":=" by "=" in the CDF definition.
Saved a lot of time.
The difference can be seen by tracing, say  Trace[cdf[1]] and Trace[cdf1[1]]
where cdf1[x_] = Integrate[f1[v],{{v, -Infinity, x}];
Best wishes.
Michael.

On Thu, Dec 3, 2009 at 6:14 AM, Nasser M. Abbasi <nma at 12000.org> wrote:

> hi;
>
> 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?
> >
>
>
>


  • Prev by Date: Re: How to make large graphics object fit within a plot?
  • Next by Date: Re: Combine images, Show[] and its effect on AspectRatio. Plot, Epilog,
  • Previous by thread: Re: piecewice pdf, problems with cdf
  • Next by thread: Re: Is it feasible? ver 7.