# Plot multiple functions with different but overlapping intervals

Suppose I numerically solve a differential equation by using

sol = ParametricNDSolve[{y'[x] == b y[x], y == 1}, y, {x, 0, 0.3}, {b}]


And then I want to plot $y[x]$ for $b=0.1,0.2,0.3$ on intervals $[0,b]$ in the same graph. How can that be achieved? Or more generally, plots on, e.g., $[0,0.2],[0,0.4],[0,0.6]$ respectively?

I use Evaluate$[\cdots]$ to enable the coloring, as

Plot[Evaluate[Table[y[b][x] /. sol, {b, 0.1, 0.3, 0.1}]], {x, 0, 0.3}]


and I would like to keep the coloring. • Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Feb 1 '16 at 11:06
• Your Plot code for y[b]'[x] doesn't match the graph, which looks like y[b][x]. – Chris K Feb 1 '16 at 15:13
• @ChrisK, Thanks, I didn't notice that. Now it is corrected. – Glenn Feb 1 '16 at 16:57

You can use a custom Piecewise function for the plotting,

Plot[Evaluate[
Table[Piecewise[{{y[b][x], x <= b}}, Null] /.
sol, {b, {0.3, 0.2, 0.1}}]], {x, 0, 0.3}] • clever solution! +1) – user36273 Feb 1 '16 at 15:35

How about changing the domain {x,0,b} and adding an "ExtrapolationHandler" to your NDSolve, as:

sol = ParametricNDSolve[{y'[x] == b y[x], y == 1}, y, {x, 0, b}, {b},
"ExtrapolationHandler" -> {Indeterminate&, "WarningMessage"->False}]

Plot[Evaluate[Table[y[b][x] /. sol, {b, 0.1, 0.3, 0.1}]], {x, 0, 0.3}] sol = ParametricNDSolve[{y'[x] == b y[x], y == 1}, y, {x, 0, 0.3}, {b}]
Show@Table[Plot[y[b][x] /. sol, {x, 0, 0.6}], {b, {0.6, 0.4, 0.2}}] supplement

You can plot it according to your needs.

Show@Table[Plot[y[b][x] /. sol, {x, 0, b}], {b, {0.3, 0.2, 0.1}}] Plot[Evaluate[Table[y[b][x] /. sol, {b, {0.3, 0.2, 0.1}}]], {x, 0,
0.3}, PlotRange -> All, PlotLegends -> {0.3, 0.2, 0.1}] • Thanks for the answer. But I want to plot $y[x]$ for $b=0.1$ on interval $[0, 0.1]$, and for $b=0.2$ on $[0, 0.2]$, and so on, not on the same interval or domain. – Glenn Feb 1 '16 at 11:22
• You can simply replace {x, 0, 0.6} with {x, 0, b}. – b.gates.you.know.what Feb 1 '16 at 12:30
• Oh, that works. But I forgot to mention that I also need to do the coloring. And Show[] seems not to be able to do that. – Glenn Feb 1 '16 at 13:13