Function plots in 2D
This functionality does not run in MATLAB.
plotfunc2d(f1, f2, …
, <Colors = [c_{1}, c_{2}, …]
>, <attributes
>) plotfunc2d(f1, f2, …
,x = x_{min} .. x_{max}
, <Colors = [c_{1}, c_{2}, …]
>, <attributes
>) plotfunc2d(f1, f2, …
,x = x_{min} .. x_{max}
,a = a_{min} .. a_{max}
, <Colors = [c_{1}, c_{2}, …]
>, <attributes
>)
plotfunc2d(f1, f2, ...)
generates a 2D plot
of the univariate functions f1
, f2
etc.
We strongly recommend reading the introduction to plotfunc2d
in Section 2.1
("2D Function Graphs") of the plot document.
The functions to be plotted must not contain any symbolic parameters
apart from the variable x
and the animation parameter a
.
Exact numerical values such as PI
, sqrt(2)
etc.
are accepted.
Animations are triggered by specifying a range a =
a_{min} .. a_{max}
for
a parameter a
that is different from the indedependent
variable x
. Thus, in animations, both the xrange x
= x_{min} .. x_{max}
as
well as the animation range a = a_{min} ..
a_{max}
must be specified. See Example 2.
Nonreal function values are ignored. See Example 3.
Functions with singularities are handled. See Example 4 and Example 5. If unbounded functions
are plotted, the vertical viewing range is clipped, automatically.
An explicit vertical viewing range ymin .. ymax
may
be requested via ViewingBoxYRange
= `y_{min}`
.. `y_{max}`
or YRange = `y_{min}` .. `y_{max}`
.
Discontinuities and piecewise defined functions are handled. See Example 6 and Example 7.
The plot
library provides the routine plot::Function2d
which
allows to create a function graph as a graphical primitive, and to
combine it with other graphical objects.
A variety of graphical attributes can be specified for fine
tuning the graphical output. Such attributes are passed as equations AttributeName
= AttributeValue
to
the plotfunc2d
command.
Section 2.3 ("Attributes for plotfunc2d and plotfunc3d") provides an overview of the available attributes.
In particular, all attributes accepted by the graphical primitive plot::Function2d
for
function graphs are accepted by plotfunc2d
. These
attributes allow to specify the mesh for the numerical evaluation,
the line width etc. The help page
of plot::Function2d provides a concise list.
Further, all attributes accepted by plot::CoordinateSystem2d
are accepted
by plotfunc2d
. These attributes include the specification
of a viewing box, of the axes, their tick marks and tick labels, the
coordinate type (such as linear versus logarithmic plots), grid lines
etc. The help page of plot::CoordinateSystem2d provides
a concise list.
Further, all attributes accepted by plot::Scene2d
are accepted by plotfunc2d
.
These attributes include the specification of the layout of the graphical
scene, the background color etc. The help
page of plot::Scene2d provides a concise list.
Further, all attributes accepted by plot::Canvas
are accepted by plotfunc2d
.
These attributes include the specification of the size of the graphics,
of further layout parameters etc. The help
page of plot::Canvas provides a concise list.
A graphical attribute such as Mesh
= 500
(setting
the number of mesh points for the numerical evaluation to 500)
is applied to all functions in the call plotfunc2d(f_{1},
f_{2}, …)
. If separate attributes
are appropriate, use the equivalent call
plot(plot::Function2d(f_{1}, attr_{1}),
plot::Function2d(f_{2}, attr_{2}),
…)
,
in which the attributes attr_{1}
, attr_{2}
etc.
can be set separately for each function.
Apart from few exceptions, plotfunc2d
uses
the standard default values for the graphical attributes (see the
help page of plot::Function2d
).
The exceptions are:
If more than one function is plotted, plotfunc2d
automatically
creates a legend. Use an explicit LegendVisible
= FALSE
to
suppress the legend.
AdaptiveMesh
is set to 2,
i.e., plotfunc2d
uses adaptive function evaluation
unless AdaptiveMesh
= 0
is requested
in plotfunc2d
.
If a parameter range such as x = `x_{min}`
.. `x_{max}`
is passed to plotfunc2d
,
the name x
is used as the title for the horizontal
axis. Pass the attribute XAxisTitle
if a different
label for the horizontal axis is desired.
The function is sensitive to the environment variable DIGITS
which
determines the numerical working precision. Make sure that DIGITS
is
set to a sufficiently small value (such as the default value 10)
to avoid the costs of computing unnecessarily precise plot data.
The following command draws the sine function and the cosine function on the interval [ π, π]:
plotfunc2d(sin(x), cos(x), x = PI .. PI):
With the attribute Scaling
= Constrained
,
the yaxis
has the same scale as the xaxis:
plotfunc2d(sin(x), cos(x), x = PI .. PI, Scaling = Constrained):
When creating an animation, a range for the independent variable x must be specified. An additional second range triggers the animation:
plotfunc2d(sin(x  a), cos(x + 2*a), x = PI .. PI, a = PI .. PI)
Only real function values are plotted:
plotfunc2d(sqrt(1  x), sqrt(x), x = 2 .. 2):
The following functions have singularities in the specified interval:
plotfunc2d(x/(x^3  4*x), x = 5 .. 5):
plotfunc2d(1/sin(x), tan(x), x = 0 .. 2*PI):
Note that the automatic clipping may in some cases lead to an incorrect impression, such as the following image where the function appears to converge to about  4.6 (but actually goes to  ∞ for small absolute values of x:
plotfunc2d(ln(abs(x)))
In this case, the asymptote which points to the pole is not seen because of the axis:
plotfunc2d(ln(abs(x)), Axes=Boxed)
We specify a vertical range to which the function graph is restricted:
plotfunc2d(tan(x), x = 3 .. 3, YRange = 10 .. 10):
The following function has a jump discontinuity:
plotfunc2d((x^2  x)/(2*abs(x  1)), x = 3 .. 3, YRange = 3 .. 3)
Piecewise defined functions are handled:
f := piecewise([x < 1, x^2 + 1], [x >= 1, x]): plotfunc2d(f(x), x = 3 .. 3, YRange = 3 .. 3, GridVisible = TRUE, TicksDistance = 1)
f := piecewise([x <= 0, x], [x > 0, 1/x]): plotfunc2d(f(x), x = 3 .. 3, YRange = 3 .. 3, GridVisible = TRUE, TicksDistance = 1)
delete f:
We use the attribute CoordinateType
to create
a logarithmic plot:
plotfunc2d(exp(x/10) + exp(x), x = 1 .. 10, CoordinateType = LinLog)
We demonstrate various further graphical attributes in a doubly logarithmic plot:
plotfunc2d(x^2, x^3/(1 + x^(1/2)), x^3, x = 1/10 .. 10^3, CoordinateType = LogLog, Axes = Boxed, DiscontinuitySearch = FALSE, GridVisible = TRUE, TicksNumber = None, TicksAt = [[10^i $ i = 1 .. 3], [10^i $ i in {3, 0, 3, 6, 9}] ]):

The functions: arithmetical
expressions or 

The independent variable: an identifier or an indexed identifier. 

The plot range: 

The animation parameter: an identifier or an indexed identifier. 

The animation range: 

The colors for 

An arbitrary number of graphical attributes. Each attribute
is given by an equation of the form 
MuPAD^{®} graphics tool is called to render the graphical scene.
The null
()
object
is returned to the MuPAD session.
display
 plot
 plot::easy
 plotfunc3d