# 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
`AdaptiveMesh`adaptive sampling`2`
`AffectViewingBox`influence of objects on the `ViewingBox` of a scene`TRUE`
`AntiAliased`antialiased lines and points?`TRUE`
`Color`the main color`RGB::Blue`
`DiscontinuitySearch`semi-symbolic search for discontinuities`TRUE`
`Frames`the number of frames in an animation`50`
`Function`function expression or procedure
`Legend`makes a legend entry
`LegendText`short explanatory text for legend
`LegendEntry`add this object to the legend?`TRUE`
`LineColor`color of lines`RGB::Blue`
`LineWidth`width of lines`0.35`
`LineColor2`color of lines`RGB::DeepPink`
`LineStyle`solid, dashed or dotted lines?`Solid`
`LinesVisible`visibility of lines`TRUE`
`LineColorType`line coloring types`Flat`
`LineColorFunction`functional line coloring
`LineColorDirection`the direction of color transitions on lines[`0`, `1`]
`LineColorDirectionX`x-component of the direction of color transitions on lines`0`
`LineColorDirectionY`y-component of the direction of color transitions on lines`1`
`Mesh`number of sample points`121`
`Name`the name of a plot object (for browser and legend)
`ParameterEnd`end value of the animation parameter
`ParameterName`name of the animation parameter
`ParameterBegin`initial value of the animation parameter
`ParameterRange`range of the animation parameter
`PointSize`the size of points`1.5`
`PointStyle`the presentation style of points`FilledCircles`
`PointsVisible`visibility of mesh points`FALSE`
`Submesh`density of submesh (additional sample points)`0`
`TimeEnd`end time of the animation`10.0`
`TimeBegin`start time of the animation`0.0`
`TimeRange`the real time span of an animation`0.0` .. `10.0`
`Title`object title
`TitleFont`font of object titles[`" sans-serif "`, `11`]
`TitlePosition`position of object titles
`TitleAlignment`horizontal alignment of titles w.r.t. their coordinates`Center`
`TitlePositionX`position of object titles, x component
`TitlePositionY`position of object titles, y component
`VerticalAsymptotesColor`color of vertical asymptotes indicating poles`RGB::Grey50`
`VerticalAsymptotesWidth`line width of vertical asymptotes indicating poles`0.2`
`VerticalAsymptotesStyle`line style of vertical asymptotes indicating poles`Dashed`
`VerticalAsymptotesVisible`vertical asymptotes indicating poles`TRUE`
`Visible`visibility`TRUE`
`VisibleAfter`object visible after this time value
`VisibleBefore`object visible until this time value
`VisibleFromTo`object visible during this time range
`VisibleAfterEnd`object visible after its animation time ended?`TRUE`
`VisibleBeforeBegin`object visible before its animation time starts?`TRUE`
`XMax`final value of parameter "x"`5`
`XMesh`number of sample points for parameter "x"`121`
`XMin`initial value of parameter "x"`-5`
`XName`name of parameter "x"
`XRange`range of parameter "x"`-5` .. `5`
`XSubmesh`density 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, AdaptiveMesh = 3)):```

### 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.

Get trial now