3
$\begingroup$

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.

$\endgroup$
8
  • 3
    $\begingroup$ Sounds like a job for Piecewise. $\endgroup$ Jan 31 '20 at 12:45
  • $\begingroup$ Or Show...... $\endgroup$
    – Michael E2
    Jan 31 '20 at 12:46
  • 5
    $\begingroup$ When the results are complicated, please take some time to write a simple toy model that represents more or less the situation you need to solve. $\endgroup$
    – Fraccalo
    Jan 31 '20 at 12:49
  • $\begingroup$ Are the parameters for these curves completely know or estimated? If the parameters need to be estimated, are there restrictions on the join points such that the derivatives are continuous? I ask the latter question because you mention the phrase "merge smoothly". $\endgroup$
    – JimB
    Jan 31 '20 at 16:02
  • $\begingroup$ @JimB : In fact in the original problem, it is important to see the asymptotic behaviors for large and small values of $x$ axis variable. A small simplification in he curve doesn't matter. $\endgroup$ Jan 31 '20 at 17:30
4
$\begingroup$
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.

$\endgroup$
3
$\begingroup$

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

$\endgroup$
3
  • 2
    $\begingroup$ 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.) $\endgroup$
    – Michael E2
    Jan 31 '20 at 12:56
  • $\begingroup$ @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? $\endgroup$ Jan 31 '20 at 12:57
  • $\begingroup$ Feel free to fix yours. I have other work to get to... :) $\endgroup$
    – Michael E2
    Jan 31 '20 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.