# How to merge two or more curves smoothly?

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.

• Sounds like a job for Piecewise. Jan 31, 2020 at 12:45
• Or Show...... Jan 31, 2020 at 12:46
• 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. Jan 31, 2020 at 12:49
• 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".
– JimB
Jan 31, 2020 at 16:02
• @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. Jan 31, 2020 at 17:30

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}},
PlotLegends -> LineLegend[colors, {"One", "Two"}]]


Alternatively, let

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


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

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

• 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.) Jan 31, 2020 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?
– user49048
Jan 31, 2020 at 12:57
• Feel free to fix yours. I have other work to get to... :) Jan 31, 2020 at 12:59