Re: Plotting a table of piecewise functions
- To: mathgroup at smc.vnet.net
- Subject: [mg105416] Re: Plotting a table of piecewise functions
- From: dh <dh at metrohm.com>
- Date: Tue, 1 Dec 2009 06:28:10 -0500 (EST)
- References: <hf2mm2$i8o$1@smc.vnet.net>
michael partensky 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. > > Hi Michale, if you simply say: Plot[pdf[x],{x,0,4}] Plot thinks, because Plot has the attribute holdAll, that you are plotting one single function. Therefore to expand pdf[x], say e.g.: Plot[Evaluate@ pdf[x], {x, 0, 10}, PlotRange -> All] Daniel