# Plotting a function that is a function of another function

I am trying to plot the following graph for different values of t (t=1 to t=10) in one plot.

Plot[Sqrt[a[x/x0[t], t]], {x, 0, x0[t]},
PlotRange -> {{0, 14}, {0, 6}}]


When I use

 Plot[Sqrt[a[x/x0[1], 1]], {x, 0, x0[1]},
PlotRange -> {{0, 14}, {0, 6}}]


I get a correct output. However, when I use this in a for loop (as follows) I get no output.

For[t = 1, t < 10, t++,
Plot[Sqrt[a[x/x0[t], t]], {x, 0, x0[t]},
PlotRange -> {{0, 14}, {0, 6}}]]

• Maybe wrap a Print around your Plot[...] Or try a[u_,v_]:=u^3;x0[t_]:=t^4; Table[ Plot[Sqrt[a[x/x0[t], t]],{x,0,x0[t]},PlotRange->{{0,14},{0,6}}],{t,1,10}] but we are just guessing what your a[u_,v_] and your x0[t] are
– Bill
Commented Jul 10 at 15:47
• Thanks. These both work but show many graphs at output. Is there any way one could show them all in one graph with different colors for different values of t? @Bill Commented Jul 10 at 16:05

You can generate the plots using Table and combine them into one plot with Show.

You don't define the functions a and x0 in your question, so I use dummy definitions as an example:

a[y_, t_] := 2 y^2 + 2 t;
x0[t_] := t + 4;

plot = Show[
Table[
Plot[Sqrt[a[x/x0[t], t]], {x, 0, x0[t]},
PlotRange -> {{0, 14}, {0, 6}}, PlotStyle -> ColorData[97][t]],
{t,10}]
]


This gives

If you want to a legend showing the color of each t value, first create the legend:

legend = LineLegend @@ Transpose[Table[{ColorData[97][t], t}, {t, 10}]]


then combine it with the plot

Legended[plot, legend]

• Is it possible to show what t value each color is related to? Commented Jul 10 at 16:46
• yes, see my edit for how to add a legend
Commented Jul 10 at 16:53
• would it be possible to add the legend label "t" to the legend too? Commented Jul 10 at 17:05
• yes. Check the documentation of LineLegend for ways to format the legend. The option LegendLabel adds a label.