Tag Archives: functions

How to plot curves with different domains in Mathematica

Mathematica (or the Wolfram language) is a very useful tool to plot functions. Suppose you are interested in plotting two curves in the same diagram, let’s say y = 1/x and z = 2/x. Both functions have the same domain of x belonging to the [0,10] interval. This is easily accomplished by typing:

Plot[{1/x, 2/x}, {x, 0, 10}]

 

Suppose now that you would like to plot in the same diagram both functions but the domain of z change to x belonging to the [2,12] interval. How could you do this? This is not difficult. You just need to use the command show with the option PlotRange->All. Here is a piece of code that accomplish this:

p1 = Plot[{1/x}, {x, 0, 10}]

p2 = Plot[{2/x}, {x, 2, 11}]

Show[p1, p2, PlotRange->All]