I guess this is more of an informatic question. A quite complicated function of mine generates me a list of valid points, depending on a parameter, like this:
valid[g_?NumericQ] := Table[g^(i/6), {i, If[g < 1.5, 2, If[g < 2, 4, 6]]}]
valid[1]
{1, 1}
valid[1.3]
{1.0447, 1.09139}
valid[1.6]
{1.08148, 1.16961, 1.26491, 1.36798}
valid[2.1]
{1.13163, 1.28058, 1.44914, 1.63988, 1.85574, 2.1}
So the number of valid points is variable (between 2 and 6). So what I want to do now is to plot these efficiently. What I inefficiently did was
v1=DiscretePlot[valid[g][[1]],{g,1,3,0.01}]
v2=DiscretePlot[valid[g][[2]],{g,1,3,0.01}]
v3=DiscretePlot[valid[g][[3]],{g,1,3,0.01}]
v4=DiscretePlot[valid[g][[4]],{g,1,3,0.01}]
v5=DiscretePlot[valid[g][[5]],{g,1,3,0.01}]
v6=DiscretePlot[valid[g][[6]],{g,1,3,0.01}]
Show[v1, v2, v3, v4, v5, v6, PlotRange -> {{1, 3}, {1, 3}}]
which, as you can imagine, takes quite a while, since Mathematica has to calculate valid[g] six times instead of one. I played around with Module, but that didn't work out for me. As a clarification, what "Show" gives me is pretty much what I want; I just would like a more efficient solution.
EDIT:
Ok, so what I do now, I let him generate the Table with all values once:
valid[g_?NumericQ] := PadRight[Table[g^(i/6), {i, If[g < 1.5, 2, If[g < 2, 4, 6]]}],6,Missing[]]
validg = Table[ valid[g],{g,1,3,0.01}]
and then I do the partial DiscretePlots:. Ok, that should work! Thank you all :)
EDiT2: Though i'm fine with the solution, you might not be, so i'll give a further constraint: i can not really change "valid[]", but have to work with it's output, since it is based on this: Updating Wagon's FindAllCrossings2D[] function
valid[1.5]
will not have a third element, sovalid[1.5][[3]]
should not work in your plot, no? Consider usingIndeterminate
orMissing[]
to fill in for invalid outputs, which can then be handled by plotting functions. $\endgroup$valid
to always output a list with six elements, and use something for filling in "invalid" values. $\endgroup$values = Table[valid[g], {g, 0, 1, 0.01}]; ListPlot[values]
$\endgroup$