MathGroup Archive 2009

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

Search the Archive

Re: Plotting a table of piecewise functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105439] Re: [mg105389] Plotting a table of piecewise functions
  • From: michael partensky <partensky at gmail.com>
  • Date: Wed, 2 Dec 2009 06:28:43 -0500 (EST)
  • References: <200912010912.EAA18696@smc.vnet.net>

Thanks a lot.
It worked.
And why are the blanks (interruptions)?
Michael.

On Tue, Dec 1, 2009 at 7:29 AM, Bob Hanlon <hanlonr at cox.net> wrote:

>
> Convert cells to InputForm prior to copy and paste to e-mail.
>
> pdf[x_] = {
>   Piecewise[{{x^2/9, 0 <= x <= 3}}],
>   Piecewise[{{x/4, 0 < x < 2}, {1/2, 2 <= x < 3}}],
>   Piecewise[{{4 x Cos[x]^2/Pi^2, 0 < x < Pi}}]};
>
> Attributes[Plot]
>
> {HoldAll,Protected}
>
> Since Plot has attribute HoldAll, until pdf[x] is evaluated pdf[x] is a
> single entity not a list, so Plot allocates it a single color.
>
> Use Evaluate to force its evaluation early. With Evaluate it is equivalent
> to your manually entering the three terms.
>
> Plot[Evaluate[pdf[x]], {x, -1, 4},
>  PlotStyle -> {Red, Green, Blue}]
>
> cdf[x_] = Assuming[{Element[x, Reals]},
>   Integrate[pdf[t], {t, -Infinity, x}]];
>
> Plot[Evaluate[cdf[x]], {x, -1, 4},
>  PlotStyle -> {Red, Green, Blue}]
>
>
> Bob Hanlon
>
> ---- michael partensky <partensky at gmail.com> wrote:
>
> =============
> Hi!
> I have a table of three piecewise functions:
>
> pdf[x]= {\[Piecewise] {
>   {(x^2/9), 0 <= x <= 3},
>   {0, \!\(\*
>      TagBox["True",
>       "PiecewiseDefault",
>       AutoDelete->False,
>       DeletionWarning->True]\)}
>  }, \[Piecewise] {
>   {0.25 x, 0 < x < 2},
>   {0.5, 2 <= x < 3},
>   {0, \!\(\*
>      TagBox["True",
>       "PiecewiseDefault",
>       AutoDelete->False,
>       DeletionWarning->True]\)}
>  }, \[Piecewise] {
>   {((4 x Cos[x]^2)/\[Pi]^2), 0 < x < \[Pi]},
>   {0, \!\(\*
>      TagBox["True",
>       "PiecewiseDefault",
>       AutoDelete->False,
>       DeletionWarning->True]\)}
>  }}
>
> I would like to make a plot of it.
>
> Plot[pdf[x],{x,-1,4},PlotStyle->{Red,Green,Blue}] ignores the colors and
> interrupts some of the curves .
>
>
>
> Plot[{pdf[x][[1]],pdf[x][[2]],pdf[x][[3]]},{x,-1,4},PlotStyle->{Red,Green,Blue}]
> does the job as expected.
>
> Why are the results different? What is wrong with the first approach?
>
> Thanks.
> Michael.
>
>
>


  • Prev by Date: Re: Combine images, Show[] and its effect on
  • Next by Date: Re: Re: Combine images, Show[] and its effect
  • Previous by thread: Plotting a table of piecewise functions
  • Next by thread: Integrating with HypergeometricU