# 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[0] == 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! Feb 1, 2016 at 11:06
• Your Plot code for y[b]'[x] doesn't match the graph, which looks like y[b][x]. Feb 1, 2016 at 15:13
• @ChrisK, Thanks, I didn't notice that. Now it is corrected. Feb 1, 2016 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, 2016 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[0] == 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[0] == 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. Feb 1, 2016 at 11:22
• You can simply replace {x, 0, 0.6} with {x, 0, b}. Feb 1, 2016 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. Feb 1, 2016 at 13:13