3

I have plotted three curves. For each range of $x$, one of those curves is true. On the other hand, finally, the result must be a unified curve. Is there any command to unify these three curves?

Actually the results are so complicated to bring here (Sorry)! However, I have brought a toy-model in following:

Plot[{1 - 1/R, R^3 - 1}, {R, 0, 5}, PlotRange -> {-2, 2}, 
 PlotLegends -> {"One", "Two"}]

It is worth mentioning that, I want the final curve to be as follows:

  • After (before) the first (second) intersection point, it should be curve two and elsewhere, curve One. Note that it is an approximation and the final plot should be kind of smooth.

  • This is the figure of my original problem. The blue dashed curve (only the right part)+the solid black one should be like the blue curves of the right panel.

This is the figure of my original problem. The blue dashed curve (only the right part)+the solid black one should be like the blue curves of the right panel.

Perfect Fluid
  • 693
  • 3
  • 13

2 Answers2

4
colors = ColorData[97] /@ {1, 2}; 

Plot[Min[{1 - 1/R, R^3 - 1}], {R, 0, 5}, 
 PlotRange -> {-2, 2}, 
 MeshFunctions -> {#^3 - 1 - (1 - 1/#) &},  
 Mesh -> {{0}}, 
 MeshShading -> Reverse[colors],
 PlotLegends -> LineLegend[colors, {"One", "Two"}]]

enter image description here

Alternatively, let

pw = PiecewiseExpand @ Min[{1 - 1/R, R^3 - 1}]

enter image description here

and use pw as the first argument in Plot above to get the same picture.

kglr
  • 394,356
  • 18
  • 477
  • 896
3

Edit: The suggestion by Michael E2 has been taken into account.

If you don't want different colours for the different regions the following does the trick for you

Plot[Piecewise[{{x^3, -10 < x < 0}, {Log[x], 0 < x < 5}, {Sqrt[x], 5 < x < 10}}], 
  {x, -10, 10}, PlotRange -> {{-1.5, 1.5}, {-2, 1}}, Exclusions -> None]

If you want different colours for the different bits, you can find an excellent analysis here

  • 2
    Might want to add Exclusions -> None if the curves are to be "unified." (Works better if the example functions join smoothly as the OP thinks theirs will.) – Michael E2 Jan 31 '20 at 12:56
  • @MichaelE2 plus one. I totally missed that. Do you want to post a precise answer so I can delete mine or should I just add you suggestion? –  Jan 31 '20 at 12:57
  • Feel free to fix yours. I have other work to get to... :) – Michael E2 Jan 31 '20 at 12:59