Prof. Vladimir A. Dobrushkin
This tutorial contains many R scripts. You, as the user, are free to use all codes for your needs, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately. Any comments and/or contributions for this tutorial are welcome; you can send your remarks to
There are two types of discontinuous functions. There are piecewise functions and functions that are discontinuous at a point. A piecewise function is a function defined by different functions for each part of the range of the entire function. A discontinuous function is a function that has a discontinuity at one or more values mainly because of the denominator of a function is being zero at that points. For example, if the denominator is (x-1), the function will have a discontinuity at x=1.
Using Mathematica, it is easy to plot a piecewise discontinuous function.
An example of a Piecewise function is given below. There are three different functions that have been generated in a single graph. Here are two options: either exclude discontinuities (which is a default option) or connect them (with option Exclusions)
This code is very similar to the Plot command. The only difference is that you add the Piecewise Command and after
this command you enter the different components of the piecewise equation and the range for each of these components.
This code creates a graph that shows all three of the different piecewise components over the range of -3 to 5. Piecewise graphing does not create vertical lines at the boundary lines of each of the piecewise components.
Discontinuous functions can be plotted in Mathematica using the following command.
Let’s plot a piecewise function: \( f(t) = \begin{cases} t^2 , & \ 0 < t < 2 , \\ 4 - t, & \ 2 < t < 4, \\ 2, & t > 4. \end{cases} \) The function is undefined at the points of discontinuity x = 1 and x = 4.
The same function with the value of 1 at t=2:
f[t_] := Piecewise[{{Piecewise[{{t^2, 0 < t < 2}, {1, t == 2}}], 0 < t <= 2}, {Piecewise[{{4 - t, 2 < t < 4}, {2, t > 4}}], t > 2}}]
Plot[f[t], {t, 0, 10}, PlotRange -> Full]
To show the discrete value at t=2, we have two options:
pts := ListPlot[{{2, 1}}]
a := Plot[f[t], {t, 0, 10}, PlotRange -> Full]
Show[a, pts]
Show[a, dp]
When you are graphing discontinuous functions, often times, it can be useful to generate a vertical or horizontal asymptote. To do this, you can use the following commands:
Plot[c,{x,c1,c2}] for horizontal asymptotes. In this command, c is the value of the horizontal asymptote and c1 and c2 are the range of the graph.
It is more difficult to graph a vertical line using Mathematica than a horizontal line. One way to do this is:
Mathematica can easily add the vertical line. The range of this function is 1 to 3. Then the command calls for Mathematica to create a straight vertical gridline at x=2. None is part of the command that tells Mathematica to just make it a straight dark, non dashed line.
If you're actually using Plot (or ListPlot, etc.), the easiest solution is to use the GridLines option,
which lets you specify the x- and y-values where you want the lines drawn.
For the case of horizontal lines when using Plot the easiest trick is to just include additional constant functions
For vertical lines, there's the Epilog option for Plot and ListPlot:
Another, perhaps even easier, option would be using GridLines:
f[x_] := (x^2 z)/((x^2 - y^2)^2 + 4 q^2 x^2) /. {y -> \[Pi]/15, z -> 1, q -> \[Pi]/600}
Plot[{f[x], f[\[Pi]/15],f[\[Pi]/15]/Sqrt[2]}, {x, \[Pi]/15 - .01, \[Pi]/15 + .01}]