Plot Examples-2
2D Plots of Functions
Plots of Predefined Functions
Sin[x] and Cos[x] are predefined functions. They can be readily plotted using predefined function Plot [ ],
Plot [function [free (independent) Variable] , {free (independent) Variable , initialValue , finalValue , options (if there is any)}]
We may combine them with more then one way,
In[4]:=
{p1, p2}
Plots of User Defined Functions
It is better, to define user defined functions as f[independentVariable_] : = Expression having one independentVariable declared in the definition of the function.
Functions are expressions which have single dependent variable (y) for any defined value of the independent variable (x). The interval which independent variable spans is called ``Domain” and related dependent variable interval ``Range”.
Every function give a single dependent variable (y) value, for any defined value of the independent variable (x). This constitutes an {x,y} point in 2D projection surface. That means functions produce a distinct point in a 2D area per defined values of the independent vaiable. We can explore these points using Table [ ] function of Mathematica.
We can plot g[x] in the domain of x [0,20] with increments of 2, that will give the mapping of the points of t1 in 2D space. The procedure is explained in our paper ´´ScatterPlot.pdf”.
This not exact mapping of the t3 of course, Mathematica has produced more points for better explaining the peaks or downhills of the dataset t3. This is achieved with sophisticad curve fitting abilities of Mathematica.
Mathematica has issued normals to the x axis. This may be best understood by another less dense set.
Mathematica has fitted a curve for joing the points of the list t3.
This is another option applied to Plot [ ] function. Mathematica has produced a fitting lines like Bézier curves for joining the points of the vector supplied.
We can see all plots together :
ImageSize is another option for setting the size of the image produced by Mathematica. Alternatively it is possible to drag the edges of the image by mouse. Note that the GraphicsGrid [ ] function, produce a single image covering all the indicated plots.
The raw plot of the function y =
at the domain [0,20], show discontinous regions in the up and down peak areas as
. This is due to the range automatically chosen by Mathematica was too short to produce an adequate plot of the function in 2D space. We can add -for this case we must- to clarify by hand, what we have in mind for the range of this function when plotting with Mathematica. This is accomplished, by stating a range interval to the Plot [ ] function by means a ``PlotRange´´ option.
We can also supply an user defined plot range :
Fine. We are beginning to understand better the options for the Plot [ ] function of the Mathematica.
Manipulations
Manipulations is changing some value affecting the function definition bzw. the plot of the function by mouse.
,
}] (* u any value between
,
*)
,
}] (* u any value between
,
,with steps of dt*)
Drag a and b with mouse to some value other than 0 and you will see the plot with the new definitions for a and b.
Manipulations can only be active in Mathematica notebook files (*.nb). For publishing the notebooks contianing manipulations, one must publish them as (*.cdf) instead of [*.html or *.htm] or (*.pdf). The cdf reader is free and may be downloaded freely from Wolfram website. When published with other formats, manipulations may be observed but can not be manipulated.
Options
Plots may be enhanced using various options. Mahematica offers a multitude options that can be implemented by the user. Bu the vaste number of these options make them very difficult to master all of these. The compromise is choosing from the options the ones that more generally applied to most instances of function plotting.
Frames
Plots in Mathematica are better shown by incorporating within a frame. Frames for plots are defined as :
For RefLink[ Graphics ,paclet:ref/Graphics] , RefLink[ Plot ,paclet:ref/Plot] , and related functions, RefLink[ Frame ,paclet:ref/Frame]->{{ left , right },{ bottom , top }} specifies whether to draw a frame on each edge. With the default setting RefLink[ FrameTicks ,paclet:ref/FrameTicks]->RefLink[ Automatic ,paclet:ref/Automatic] , ticks are included whenever a frame is drawn.
Now frames become equivalents of axes. The motivation of axes/Frame interchange is the oppotunity to label the frame at the middle of the frame. This opportunity is not given to the axes specification which may only labeled at their extreme ends by their predefined function. But this is possible with using Text [ ] subroutine of the Graphics [ ] function. This will be shown at the later pages of this manuscript.
There are many options for making the labels more stylish or prone to publication.
Each label may have only one option without applying Directive rule.
The styles of the frames drawn in above plot are colored by means of FrameTicksStyle rule. It can handle only one option without calling Directive [ ] function. Mathematica has multitude of ways of specify colors. We may consult Mathematica Documents for how to specify colors and try them using this plotting template.
With Directive [ ] function we have more opportunities,
With Directive Function, we can also set FontFamily and FontSize rules together with a colored text.
Labeling of the Plot is made by applying PlotLabel rule with LabelStyle [ ] function. The Directive [ ] function may be called for more styling options.
FrameLabel → rule may be applied for labeling the edges of the frame with style. FrameLabel→None specifies that no labels should be given.
FrameLabel → label specifies a label for the bottom edge of the frame.
FrameLabel]→{ bottom , left } specifies labels for the bottom and left-hand edges of the frame.
FrameLabel→{{ left , right },{ bottom , top } specifies labels for each of the edges of the frame.
Any expression can be specified as a label.
Labels for the vertical edges of the frame are written vertically by default . For the horizontal labels we may set RotateLabel--> False
The following settings can be given for GridLines :
With the GridLines --> Automatic setting, grid lines are usually placed at points whose coordinates have the minimum number of digits in their decimal representation.
For each direction, the following grid line options can be given:
GridLines --> None , no grid lines drawn.
GridLines --> Automatic , grid lines placed automatically.
GridLines --> {xgrid , y grid} grid lines specified separately in each direction.
Grid line styles can involve any graphics directives, such as RGBColor and Thickness.
The grid line function
may return any other grid line option.
AbsoluteOptions gives the explicit form of GridLines when Automatic settins are used.
GridLinesStyle gives default styles to use for grid lines.
GridLinesStyle --> style specifies that all grid lines should be rendered by default with the specified style. /p>
GridLinesStyle --> {x style, y style} specifies that x and y grid lines should use different styles.
Styles can be specified using graphics directives such as Thick, Red and Dashed , as well as Thickness, Dashing, RGBColor and combinations given by Directive [ ].
Style specifications can refer to styles using style names from current stylesheets.
Any outside styles not explicitly overridden by settings in GridLinesStyle will still be used.
Explicit styles specified in the settings for GridLines can override styles specified in GridLinesStyle.
The default style of axes is specified by the option DefaultGridLinesStyle
For a last touch , we’ll adjust the size of the image,
We can easily watch narrower domains in order to understand better the behavior of the function. Example :
Obtaing black and white versions are more easy.
Aspect Ratio
Aspect ratio is the ratio
and may be set by the user or set as Automatic or unstated by leaving the arrangement to its default value
The deafult is 1/GoldenRatio and if it is the case, we do not have to mention it in the graph program.
Every function, except the Identity function y = x, result with different values of range for a fixed domain. Therefore the setting of aspect ratio is of ultime importance. We should consider carefully the trend of our function and choose a proper aspect ratio. By the way, for the Identity function,
We can try different aspect ratios for specific functions and find the best one that fit our needs.
Discontinuous Functions
Not All fonctions are continuous in the domain (-∞,∞) that is, some values of the dependent variable of this domain do not produce known values of the function. This is called ``discontinuation”. Discontinuation property is purely dependent of the configuration of the function. Functions which exhibit discontinuties are called ``Discontinious Functions” .
Most rational functions exhibit discontinuative property owing to certain values of x which produce
ratio, with a being a real number.
Function discontinuity is not a simple subject to tackle at once. We should get proper familiarity about the discontinuties of the functions. A website defining concisely and comprehensibly the subject is https://www.math24.net/discontinuous-functions/ . We will follow the subject from their web pages. First discontinuity map devised according the definitions of this site is presented blow:
If f(x) is not continuous at x=a, then f(x) is said to be discontinuous at this point. Figures 1−4 show the graphs of four functions, two of which are continuous at x=a and two are not.
Classification of Discontinuity Points
We will begin with discontinuities of first kind. The functions having defined limits in both sides of the point x = a , (a) being a real number in the domain of the function and the limits of the function are real and equal to each other in both sides of (a) is a function having first class removable discontiniuty which is not a jump discontinuation property. we will call these functions as ``Functions having ``A” type first class discontinuation property. Functions which exhibit jump discontinuity will be called as ``B” type first class discontinuation.
For understanding whether the function has some kind of discontinuation we will look at first to its graph. But careful : First class A type discontinuations (without a jump) can not be spotted from their graphs. Graphs may only reveal first class jump discontinuations (class B) and second kind non removable discontinuations. Then mathematical investigation in form of finding both side limits must be taken into account. We will follow these paths in examining the functions about their discontinuities.
Since we will need to find some limits and roots of equations, it is important to know, how the limits and roots of equations are found with Mathematica.
Limits in Mathematica
Limits in Mathematica are found by the application of the function Limit [ ]. The general form of application for any function f[x] defined previously .
Limit[f[x] , x → a]
For finding the lower (left) or upper (right) limit when x aproaching a,
Limit[f[x] , x → a-0] and Limit[f[x] , x → a+0]
or,
Limit[f[x] , x → a ,Direction→ -1] and Limit[f[x] , x → a Direction→1]
Limit[f[x] , x → a ,Direction→ -1] means the limit of the function f[x] when x tends to a, approaching from above. (-1 means from +∞ to -∞) or (from right to left)
Limit[f[x] , x → a ,Direction→ 1] means the limit of the function f[x] when x tends to a, approaching from below. (1 means from -∞ to 4∞) or (from left to right).
Roots of the equations with Mathematica
Mathematica include different methods for finding the roots of equations. Normally using Solve [ ] function wiil be enough to spotting the roots of most equations. but for problematic ones, one may try more sophisticated functions provided form mathematica.
Usage of Solve function is,
Solve[f[x](== for equal, < for less than, > for greater than) right side term, {independentVariable}]
We are now ready for looking after the discontinuities.
Find a discontiniuty of the function,
Solution :
Altough it not fully informative about all the discontinuities (discontinuities of the first class type A can not be understood from the graph of the function) we will always begin by investigation of the graph of a function. Bu we will not rely completely on the primary information obtained form the graph for the final decision about the discontinuity of the function examined.
The graph of this function,
The graph show a false impression so that an unaware may decide that the given function is continous. In fact it is not. Since the given function has not changed its structure and still rational after the simplification, we will examine whether the function becomes
For clarifying this situation, we will make an equation with the denominator term of the given function equals to zero. For our example,
We got number of roots, some of them are real, some of them is complex. But for tems of discontinuity real or complex values makes no difference they all cause discontinuities.
Plots of functions having discontinuities with Mathematica, result with graphs where the asymptotes are not shown. To make them visible, we have to add some options.
Plot[f, {x, a,b}, Exclusions → {list}]
Mathematica, by default take Exclusions → All, to make them visible we should turn it to Exclusions → None
Plots of Mathematica can not indicate the points where the function has type A discontinuity. We should not rely to the Mathematica plots on the subject, the final decision must be taken only after mathematical analysis.
Example
Find a discontiniuty of the function,
The neighborhood of a region where small changes of the independent variable result big changes of the dependent variable is the region of discontinuity of the function. From the graphical result, we conclude that the given function has a type 2 unremovable discontinuity at x = 1 . The plot also show that an asymptotic line exist at x = 0 . We will bring the vertical asymptote at light by adding the option, Exclusion → None.
Clearly, the function
has a vertical asymptote, normal to the x axis at point {1 , 0} indicated by the graph of the function. But we must always find the exact values by mathematical methods.
Mathematica confirms that the given function has an asimptote at x = 1 as,
Whether the upper and lower limits from each side exists, will be detected by Mathematica,
The limit examination with Mthematica, reveals that, limits in both directions in the discontinuity point x = 1, is Indeterminate in both sides.This indicates that the given function has an essential (unremovable) discontinuity named ``Discontinuity of the Second Kind” at the point x = 1.
Example
Find whether the function y =
has discontinuities.
Solution
We’ll begin by tracing its graph.
The function indicates that the given function has two discontinuities about 1 and -1, let us spot them more precisely.
The graphic output show that there is two asymptotes at -1 and 1 . More precise locations will be indicated by more detailed graphs.
It is confirmed that the given function has two discontinuities at the points x = -1 and x =1 . Let us look with a bigger image sizes,
More precise locations of aymptotic lines, are to be found by mathematical analysis.
The function structure is of type
and indeterminable when
. We will look for an x which will cause,
indeterminate. Let us simplify this rational expression.
=
=
or,
= 0 ;
= 0 ;
= 1 ;
- 1 = 0 ; (x-1)(x+1) = 0; x = 1 or x = -1
or simply
These two values make
equal to zero, this makes
indeterminate which makes in turn,
as indeterminate. The points (-1) and (1) are the discontinuity points found algebraically and they are confirmed by the graph of this function.
Upper and lower limits in the neighborhood of these points, will show the type of discontinuity of this function.
For the final result, the given function is determined to have essential, nonremovable second class discontinuities at the points x = -1 and x =1. This is supporting by mathematical anaysis and by the results obtained from graphical investigations.
Example
Find the discontinuities of the function y =
.
Solution
First we plot this function as usual :
At first sight, the function seems to be continious by its graph. But, this is not the case. We should not forget there is a single x in the denominator. When this x will be equal to zero in the range [-2 , 2] the function will have a discotinuity.
From the plot of this function, we observe that the discontinuity is not a jump discontinuty, in contrary it is a point discontinuty. This will imply also that if x will be near in both sides about ε (epsilon) the function will tend to its limit δ =1 in both side the value of the discontinuity without being equal to it. Then various types of discontiuties occur depending the structure of the function.This is first class A type removable discontinuity because the limits of both sides of the asymptotic line is real and equal to each other. This make this function piecewise, but contigious in -ε and + ε advances of the independent variable (x) before and after the point of discontinuity.
This make the function piecewise but this stay unnoticed when inspecting the graph of the function. To understand the piecewise behavior of the function we will graph each piece separately :
The plot of this function is nothing than a seamless plotting of both pieces separately but contigiously due to the sophisticated intricate plotting function of Mathematica, which plot the first order class A functions aa a single graph whose discontinuities can not be noticed by eyes. Even adding the option ``Exclusions→None” will not help for having the exlusion point be inserted within the graph.
Mathematica has a Piecewise[ ] function but this function is most useful in function having jump discontinuities and essential discontinuities . For function plotting, simple Plot [ ] function will suffice, with or without ``Exclusions→None ” option. Note that for the functions having first order class A discontinuities stating Exclusions→ All is unnecessary.
Adding Piecewise[ ] function is not enhancing the graph compared to the graph produced by a simple Plot [ ] function.
This function has a removable discontinuity at at x=0. This cannot be seen in graphs and even Mathematica does not help. The discontinuity may only be understood by finding the value of the independent variable (x) which makes the value of the function ``Unknown” and this value is conventionally considered as ``Infinity” (∞) .
The function
, for x = 0, has a limit conventionally equal to infinity (whatever the meaning is) and in this value of free variable, the left and right limits are numeric and equal to each other.
This result prove that the given function has a first class A type removable discontinuity because limits of the both sides are numeric and equal to each other. This kind of discontinuity is not remarquable by plotting but with only by mathematical analysis.
Graphs of Mathematica can also be enhanced using options or using ``Drawing Tools” of the Mathematica. Drawings tools is considerably makes adding arrows, lines, text easy avoiding time consuming programming steps.
Drawing Tools are supplied in recent versions of Mathematica and its use simplify the plot decoration, but there is constraints for using Drawings Tools.
Producing plots is a two step process. First step is the generation of plot by using predefined functions of Mathematica. The second step is to decorate the plot with texts, Lines, Arrows and other graphic objects. This can be achieved either by Graphic functions (time consuming) or Drawing Tools (fast and easy).
Drawing Tools is for plots which are ultimate. When the plot is mathematically reached at its ultimate final step, then it is more advantaguous to finish with Drawings Tool and save the image elsewhere for publishing or else.
If we plan to further inspect by altering some options, then using graphic functions will be far more better, since with every new generated version of the plot we will have the same graphic retouches included in the program steps and not by Drawings Tools. On the contrary, if we had used drawing tools we’ll have to make same retouches with drawing tools, every time the new version of the graph would be produced.
We will proceed by applying the required graphic add-ons by using Mathematica graphic functions. Adding text methods is shown below:
Graphics Primitives for Text
With the Text graphics primitive, you can insert text at any position in two - or three - dimensional Mathematica graphics. Unless you explicitly specify a style or font using Style, the text will be given in the graphic’ s base style.
Text[expr, {x, y }] [text centered at the point {x, y}
Text[expr, {x, y}, {-1, 0}] text with its left - hand end at {x, y }
Text[expr, {x, y}, {1, 0} ] right - hand end at {x, y}
Text[expr, {x, y}, {0, -1}] centered above {x, y}
Text[expr, {x, y}, {0, 1}] centered below {x, y}
Text[expr, {x, y}, {dx, dy}] text positioned so that {x, y} is at relative coordinates {dx, dy} within the box that bounds the text
Text[expr, {x, y}, {dx, dy}, {0, 1}] text oriented vertically to read from bottom to top
Text[expr, {x, y}, {dx, dy}, {0, -1}] text that reads from top to bottom
Text[expr, {x, y}, {dx, dy}, {-1, 0}] text that is upside - down
(ın two - dimensional plots).
It would be not so easy working with Mathematica graphic functions, if some previously worked examples is not at hand. A program applied below to our example, is shared by the University of Texas in Austin.
Example
Let us plot and see ,
This two functions are not a true piecewise function. These are two different functions. Their structure and domains make them to seem as piecewise.
Example
Solution
Let us plot this function :
The function has a discontinuity of the second kind (non-removable jump discontiniuty) at x =0. At least one of the side limits should be indeterminate (complex infinity).
That show that the given function has a second class nonremovable essential discontinuty. The graph of the function in this case is extremely important. The values of the function at the near vicinity of the asymptotic line tending to the different infinities is only observable from the plot of these functions. Also careful attempts to assess the values in the vicinities of the asymptotic line is also informative.
This show that the observed function is a piecewise function. Let us plot it as a piecewise function.
Example
Find the points of discontinuity of the function f(x)
The point of discontinuity :
This function is discontinous only at x =
and continious elsewhere. Let us plot and see its behavior :
The upper and lower limits :
Out[8]=
{Indeterminate, Indeterminate}
Limits at the near neighborhood of the asymptotic line at x = -2.5 is found as indeterminate. But the values of the function in sufficient distance from the asymptotic line are real but not the same. Observations from the plot of these functions is of higher importance. The graph and algebraic results reveal that this function has a discontinuity of the first kind (removable discontinuity) at the point {-2.5,0}. The first kind discontinuity is of class B (removable jump discontinuity), since the values sufficiently away from the asymptotic line are real but different from each other. This a piecewise function whose enlarged graph is shown below.
Mathematica can handle more fine tunings on piecewise functions. More information may be found in Mathematica Definitions .
Functions Plotted Together
Plotting functions together makes only sense if these functions share common domain of the common independent variable and give about the comparable values in the range of the dependent variable. Best examples may be sinus and cosinus functions.
Adding Tooltip,
Adding PlotRegion and PlotRange,
About Dashing,
Dashing is a very advanced plot option for every distinguished plotted curves.
Dashing may be
{
Dashing is evaluated as succession of {trace,leaveBlank} successions. If they are equally spaced, giving only one measure will suffice as Dashing[Tiny].
Dashing may be given as
{
Dashing[{}] means, no dash, just a solid curve as evaluated by default, therefore there is no need to state.
Adding PlotStyle,
Adding PlotLegends (added by default after the plot) ( they are also labeled by tooltips). Plot legends may be placed at “Before”,”Above”,”Below” and “After” as ex. PlotLegends → Placed[{“sin(x)”,”cos(x)”,After]. If “After is the choice, it is the default value and stating PlotLegends→ Expressions” will suffice.
Adding PlotLegends (Already visible by tooltips)
Those were for individual plots, now we can state the option for the whole plot. For avoiding the whole program to be cluttered, we have chosen to add them separateley using Show[ ] function. Since now we have all the data about the individual plots as p1. We can now call Show [ ] function to display what we have in hand for the individual plots and add the new options about the whole plot.
It is showing all the up to date options for the individual curves. These can not be reached from Show[ ].
Adding the image size for the whole curve.
Adding background color (if it is wished as white, this the default color and no need to be given).
Adding axes. Axes may turn on by True, and off by False. If both will be True, there is no need to be stated since it is the default value.
Adding AxesOrigin. Default is {0,0} if it is the choice there is no need to state explicitly.
Adding PlotLabel,
We will peserve all the options for giving a chance to alter them for a new user. Decorating the axes,
Labeling axes,
Well, the general impression is not favorable for the axes labeled at the end of the axes, so we will present another possibilities, either to frame all or place them with programming steps but if this plot is the final design the using ``Drawing Tools” is much faster for any one who is not willing to jump out to the deeper functions of the Mathematica. Any way we will continue by programming.
Axes Ticks,
Grid Lines
Configuring the grid lines,
Framing the whole plot,
Altering the image size,
Last possibility is to work direcly with the plot, by using graphic primitives and without frames,
Usage of these plot templates
Problem :
Plot y =
+
where the domain of x will be [-10 , 10]. (University of Texas in Austin)
Solution :
It is strongly advisable to make a very basic plot of any function to be plotted, ther we can see what will its behavior and assess the domain and range intervals for a detailed plot.
Well, it seems the is a second kind discontinuity at x=-10 and x=10. Let us see the limits :
We will also contol the value of the function in these pseudo asymptotic lines,
The results show that the function has no real asymptotes at the points x=-10 and x=10 . But there is no point to examine his domain beyond x=-10 and x=10 since the range evaluates to the extremely high values which are not representable by 2D x/y plots.
It is better to examine this function in the region [-5,5] :
The function seems to have a root and inflexion point at x = 0. Let’s chek it :
Right, it has actually a root at x = 0. For the evaluation of the inflexion point we’ll leave for the detailed mathematical analysis. We will only try to plot this function.
Let us import one of the templates developed at this page and presented above and change the values according to our first observations of the given function.
It has taken considerably less time for getting a presentable plot.
Problem :
Solution :
Just change the inputs with yours...
Last assays are near publication quality.
Mathematica has many other options to enhancing the plots. Here, we have only presented some of them, useful for having fully decorated plots.
Happy ploting...
N.B. : For the Mathematica notebook one should have desktop version of the latest version of Mathematica.
For the cdf version (Mathematica Computable Document Format comparable to pdf's but more advantageous to copy the including text) may be downloaded as a free cdf reader from the Wolfram web site.
For copy/paste actions rtf version may be suitable at best. This version may be downloaded and read by write.exe which is a standard and free rtf reader for windows. These documents may also read by Microsoft Word or equivalent free software.