RE: Plot several graphs generated by Table
- To: mathgroup at smc.vnet.net
- Subject: [mg36441] RE: [mg36424] Plot several graphs generated by Table
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Sat, 7 Sep 2002 02:53:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: muhnochwaaa at yahoo.com [mailto:muhnochwaaa at yahoo.com] To: mathgroup at smc.vnet.net >Sent: Friday, September 06, 2002 9:17 AM >Subject: [mg36441] [mg36424] Plot several graphs generated by Table > > >myArray is a list of triplets which look like {n,k,p}, where n and k >are integers and p is real number. repetitions in n and k are allowed >but no two triplets ar the same. > >I define a function, myfunc[n_,pthreshold_] as follows. > >myfunc[n_,pthreshold_] := Module[{t}, >t=Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> p, 2]]; >If[t>=0,t,-1]] > >It prints the largest k for which p is greater than pthreshold for a >given n and >-1 if there is no such k. The function does its job fine. > >My problem is as follows. I would like to plot a collection of plots, >myfunc[n,p], for 1<=n<=21 with respect to p. unfortunately the >following does not work as desired. > >Plot[Table[myfunc[n,p],{n,1,21}],{p,0.0,1.0}] > >because the Table gets evaluated to numeric value (-1) before Plot is >invoked. >How could I accomplish this? Thanks in advance for all your helps. > The problem with your calculation indented is (1) to evaluate Table (within Plot), which gives {myfunc[1, p], ..., myfunc[21, p]} but (2) *then* to prevent further evaluation of myfunc[.., p] to -1. There are several tricks to do so, e.g. ... Hold[Plot[toPlot, {p, 0, 1}]] /. toPlot -> Table[headPlaceholder[n, p], {n, 3}] /. headPlaceholder -> myfunc // ReleaseHold ...but in your case just simply prevent evaluation of myfunc[.., p] with p being a Symbol by defining: myfunc2[n_, pthreshold_?NumericQ] := ... now... Plot[Evaluate[Table[myfunc2[n, p], {n, 21}]], {p, 0, 1}] ...works as expected. BTW, what do you want to read off the plot, that you didn't know from Table[myfunc[n, 0], {n, 21}] ? -- Hartmut Wolf