Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# plot::Function2d

2D function graphs

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```plot::Function2d(f, options)
plot::Function2d(f, x = xmin .. xmax, <a = amin .. amax>, options)
```

## Description

plot::Function2d creates the 2D graph of a univariate function.

The graphics ignores all points, where the expression/function f does not produce a numerical real value. See Example 2.

The expression/function f may have singularities in the plot range. Although a heuristics is used to find a reasonable y range when singularities are present, it is highly recommended to specify a y range via ViewingBoxYRange = `y_{min}` .. `y_{max}` with suitable numerical real values ymin, ymax. See Example 3.

Animations are triggered by specifying a range a = `a_{min}` .. `a_{max}` for a parameter a that is different from the independent variable x. Thus, in animations, both the x-range x = `x_{min}` .. `x_{max}` as well as the animation range a = `a_{min}` .. `a_{max}` must be specified. See Example 4.

The function f is evaluated on an equidistant mesh of sample points determined by the attribute XMesh (or the shorthand notation Mesh). By default, the attribute AdaptiveMesh = 0 is set, i.e., no adaptive refinement of the equidistant mesh is used.

If the standard mesh does not suffice to produce a sufficiently detailed plot, one may either increase the value of XMesh or set AdaptiveMesh = n with some (small) positive integer n. If necessary, up to 2n additional points are placed between adjacent points of the initial equidistant mesh. See Example 5.

By default, the attribute DiscontinuitySearch = TRUE is set. This triggers a semi-symbolic preprocessing of the expression f to search for discontinuities and singularities. At each singular point, the function graph is split into disjoint branches to the left and to the right of the singularity. This avoids graphical artifacts such as lines connecting points to the left and to the right of a singularity.

If the function is known to be regular in the plot range, the semi-symbolic search may be disabled by specifying DiscontinuitySearch = FALSE. This will improve the efficiency of the plot commands.

Singular points are highlighted by a vertical line unless VerticalAsymptotesVisible = FALSE is specified. Its style may be set by the attributes VerticalAsymptotesStyle, VerticalAsymptotesWidth, and VerticalAsymptotesColor.

 Note:   This functionality is only available if the function is specified by a an arithmetical expression or a procedure that accepts symbolic arguments. It is not available if the function is specified by a piecewise object or by a procedure that accepts only numerical arguments.

See Example 6.

plot::Hatch allows to hatch areas between function graphs. See Example 7.

## Attributes

AttributePurposeDefault Value
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
AntiAliasedantialiased lines and points?TRUE
Colorthe main colorRGB::Blue
DiscontinuitySearchsemi-symbolic search for discontinuitiesTRUE
Framesthe number of frames in an animation50
Functionfunction expression or procedure
Legendmakes a legend entry
LegendTextshort explanatory text for legend
LegendEntryadd this object to the legend?TRUE
LineColorcolor of linesRGB::Blue
LineWidthwidth of lines0.35
LineColor2color of linesRGB::DeepPink
LineStylesolid, dashed or dotted lines?Solid
LinesVisiblevisibility of linesTRUE
LineColorTypeline coloring typesFlat
LineColorFunctionfunctional line coloring
LineColorDirectionthe direction of color transitions on lines[0, 1]
LineColorDirectionXx-component of the direction of color transitions on lines0
LineColorDirectionYy-component of the direction of color transitions on lines1
Meshnumber of sample points121
Namethe name of a plot object (for browser and legend)
ParameterEndend value of the animation parameter
ParameterNamename of the animation parameter
ParameterBegininitial value of the animation parameter
ParameterRangerange of the animation parameter
PointSizethe size of points1.5
PointStylethe presentation style of pointsFilledCircles
PointsVisiblevisibility of mesh pointsFALSE
Submeshdensity of submesh (additional sample points)0
TimeEndend time of the animation10.0
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0
Titleobject title
TitleFontfont of object titles[" sans-serif ", 11]
TitlePositionposition of object titles
TitleAlignmenthorizontal alignment of titles w.r.t. their coordinatesCenter
TitlePositionXposition of object titles, x component
TitlePositionYposition of object titles, y component
VerticalAsymptotesColorcolor of vertical asymptotes indicating polesRGB::Grey50
VerticalAsymptotesWidthline width of vertical asymptotes indicating poles0.2
VerticalAsymptotesStyleline style of vertical asymptotes indicating polesDashed
VerticalAsymptotesVisiblevertical asymptotes indicating polesTRUE
VisiblevisibilityTRUE
VisibleAfterobject visible after this time value
VisibleBeforeobject visible until this time value
VisibleFromToobject visible during this time range
VisibleAfterEndobject visible after its animation time ended?TRUE
VisibleBeforeBeginobject visible before its animation time starts?TRUE
XMaxfinal value of parameter "x"5
XMeshnumber of sample points for parameter "x"121
XMininitial value of parameter "x"-5
XNamename of parameter "x"
XRangerange of parameter "x"-5 .. 5
XSubmeshdensity of additional sample points for parameter "x"0

## Examples

### Example 1

The following call returns an object representing the graph of the sine function over the interval [0, 2 π]:

`f := plot::Function2d(sin(x), x = 0 .. 2*PI)`

Call plot to plot the graph:

`plot(f):`

Functions can also be specified by piecewise objects or procedures:

```f := piecewise([x < 1, 1 - x], [x >= 1, x^2]):
plot(plot::Function2d(f, x = -2 .. 4)):```

```f := proc(x)
begin
if x^2 - 2*x < 0 then
0
else
x^2 - 2*x
end_if:
end_proc:
plot(plot::Function2d(f, x = -2 .. 4)):```

`delete f:`

### Example 2

Non-real values are ignored in a plot:

```plot(plot::Function2d(sqrt(1 - x^2), x = -2 .. 2),
Scaling = Constrained):```

### Example 3

We plot a function with singularities:

```f := plot::Function2d(sin(x)/(1 - x) - 1/cos(x), x = 0 .. PI):
plot(f):```

We specify an explicit viewing range for the y direction:

`plot(f, ViewingBoxYRange = -20 .. 10):`

`delete f:`

### Example 4

We generate an animation of a parametrized function:

```plot(plot::Function2d(a*sin(x) + (1 - a)*cos(x),
x = -PI .. PI, a = 0 .. 1)):```

### Example 5

The standard mesh for the numerical evaluation of a function graph does not suffice to generate a satisfying graphics in the following case:

`plot(plot::Function2d(sin(PI/x), x = -1 .. 1)):`

We increase the number of mesh points:

`plot(plot::Function2d(sin(PI/x), x = -1 .. 1, XMesh = 1000)):`

Alternatively, we enable adaptive sampling by setting AdaptiveMesh to some positive value:

`plot(plot::Function2d(sin(PI/x), x = -1 .. 1, AdaptiveMesh = 3)):`

Finally, we increase the XMesh value and use adaptive sampling:

```plot(plot::Function2d(sin(PI/x), x = -1 .. 1, XMesh = 1000,

### Example 6

With VerticalAsymptotesVisible = TRUE/FALSE, singular points are highlighted by a vertical asymptote, or this highlighting is switched off, respectively:

```plot(plot::Function2d(ln(x + PI) + 1/(x - 1) - 1/(x + 1)^2,
x = -4 .. 4,
VerticalAsymptotesVisible = TRUE,
ViewingBoxYRange = -10 .. 10)):```

```plot(plot::Function2d(ln(x + PI) + 1/(x - 1) - 1/(x + 1)^2,
x = -4 .. 4,
VerticalAsymptotesVisible = FALSE,
ViewingBoxYRange = -10 .. 10)):```

### Example 7

The plot::Hatch object allows to hatch regions between functions. It expects graphical objects of type plot::Function2d or plot::Curve2d as boundaries:

```f1:= plot::Function2d(sin(x), x = -PI .. 2*PI):
f2:= plot::Function2d(cos(x), x = -PI .. 2*PI):
plot(f1, f2, plot::Hatch(f1, f2, -1 .. 5)):```

`delete f1, f2:`

## Parameters

 f The function: an arithmetical expression or a piecewise object in the independent variable x and the animation parameter a. Alternatively, a procedure that accepts 1 input parameter x or 2 input parameters x, a and returns a real numerical value when the input parameters are numerical. f is equivalent to the attribute Function. x The independent variable: an identifier or an indexed identifier. x is equivalent to the attribute XName. xmin .. xmax The plot range: xmin, xmax must be numerical real values or expressions of the animation parameter a. If not specified, the default range x = -5 .. 5 is used. xmin .. xmax is equivalent to the attributes XRange, XMin, XMax. a Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.