Previous Page Next Page Contents

plot::Function2d -- graphical primitive for a two-dimensional graph of a function

Introduction

plot::Function2d(f, x = a..b) represents a plot of the function f(x) with x in [a,b].

Creating Elements

plot::Function2d(f, x = a..b <, option1, option2...>)
plot::Function2d(f, x = a..b, y = ymin..ymax <, option1, option2...>)

Parameters

f - arithmetical expression in x
x, y - identifiers
a, b, ymin, ymax - arithmetical expressions
option1, option2, ... - plot option(s) of the form OptionName = value

Related Domains

plot::Curve2d, plot::Function3d, RGB

Related Functions

plot, plot2d, plotfunc2d, plot::copy

Details

Option: Discont =

value

Option: RealValuesOnly =

value

Operands

An object of plot::Function2d consists of three operands. The first operand is the term f of the function. The second one is the variable x of the term and its range in the form x = a..b. The third one is the value Automatic, or the range ymin..ymin if the parameter y = ymin..ymax was given.

Important Operations

Operands of a function primitive can be accessed either using the system function op, the index operator [ ], or using the attributes described above. For example, if function is such an object, then the calls op(function,1), function[1] and function::term return the term f.

Via function[1] := f or function::term := f, the term of a function primitive can be changed.

See the methods "op", "_index", "set_index" and "slot" below.

Use the slot operator :: to get or set plot options of such objects afterwards, i.e., when they have been created. For example, if function is such an object, then function::Color := RGB::Red changes the color of the function primitive function to red.

Result of Evaluation

Evaluating an object of type plot::Function2d returns itself.

Function Call

Calling an object of plot::Function2d as a function yields the object itself, regardless of the arguments. The arguments are not evaluated.

Entries

defaultOptions

is a table of plot options for function primitives and their default values. Each entry has the form OptionName = default_value.

When an object of the domain plot::Function2d is created, then a copy of this table is stored under the attribute options (see the table of attributes above), where those options are added and replaced, respectively, which are given by the (optional) parameters option1, option2... of the creating call (see ``Creating Elements'' above).

Plot options, which are not contained in the table stored under the attribute options will not be included in the plot data of the object created by the method "getPlotdata" (see below).

For those options, the corresponding default value either is set by a graphical scene, if the option also exists as a scene option (such as the option PointWidth), or it is internally set by the function plot2d which is used to plot the object. See the table of plot options above, which gives a summary of the available plot options for function primitives and their default values. See example 4.

To change the default value of some plot options, the option name and its default value may be added to the table "defaultOptions", or replaced by a new value, respectively.

optionNames

is a set of the available option names for plots of two-dimensional graphs of functions.

Method _index: indexed access to the operands of a function primitive

Method dimension: dimension of a function primitive

Method getPlotdata: the plot data of a function primitive

Method nops: number of operands of a function primitive

Method op: extract operands of a function primitive

Method set_index: set operands of a function primitive

Method slot: read and write attributes and plot options

Method checkOption: check a plot options

Method copy: create a copy of a function plot

Method modify: modify a copy of a function plot

Method print: print a function primitive

Example 1

The following call returns an object representing the graph of the sine function in the interval [0, 2*PI]:

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

To plot the graph in a graphical scene, call plot:

>> plot(f)

To restrict the y-range of the graph, for example, to the interval [0,1], specify a second range in the call of plot::Function2d:

>> f2 := plot::Function2d(sin(x), x = 0..2*PI, y = 0..1):
   plot(f)

The variable of the second range can be any identifier, that, of course, differs from the variable of the function term (here: x).

Plot options of the curve can be given as additional parameters in the creating call, such as plotting the graph in green color and changing its style so that it is drawn as impulses:

>> f3 := plot::Function2d(sin(x), x = 0..2*PI, 
     Color = RGB::Green, Style = [Impulses]
   )
                   plot::Function2d(sin(x), x = 0..2 PI)
>> plot(f3)

To change default values of some scene options, pass the scene options to the call of plot as additional arguments. For example, to draw grid lines in the background of the plot, call:

>> plot(f, GridLines = Automatic)

See the help page of plot::Scene for available scene options.

Example 2

We want to plot a graph of the sequence n -> sin(n)/n in the interval [1, 50], enclosed by the graphs of the functions x -> 1/x and x -> -1/x. We start by creating the three different graphical primitives as follows:

>> f1 := plot::Function2d(1/x, x = 1..50);
   f2 := plot::Function2d(-1/x, x = 1..50);
   a  := plot::Pointlist([n, sin(n)/n] $ n = 1..50, Color = RGB::Blue)
                                     / 1            \
                     plot::Function2d| -, x = 1..50 |
                                     \ x            /
      
                                    /   1            \
                    plot::Function2d| - -, x = 1..50 |
                                    \   x            /
      
                             plot::Pointlist()

To plot the scene of these objects, pass them as parameters to the function plot:

>> plot(f1, f2, a)

Example 3

The process of the clipping the graph of a function plot can fail and produce plots outside the specified rectangle. This is the case, for example, if the function strongly oscillates in the given interval.

Consider the function sin(exp(x)) for x in [-5, 5]. We are interested only in the positive part of the graph, and thus enter:

>> f := plot::Function2d(sin(exp(x)), x = -5..5, y = 0..1):
   plot(f)

The clipping of the graph fails in this example (see the note in the ``Details'' above). It can be helpful in such cases to increase the value of the option Grid:

>> f::Grid:= [500]: plot(f)

Example 4

If a function primitive is created, values of some plot options of the created object can be read, or replaced by new values.

To illustrate this, we create the following function:

>> f1 := plot::Function2d(1/x^2, x = -5..5, Color = RGB::Blue)
                                     / 1             \
                     plot::Function2d| --, x = -5..5 |
                                     |  2            |
                                     \ x             /

We create a copy of the graph, change some plot options of the copied object, and plot both objects in a graphical scene:

>> f2 := plot::copy(f1): 
   f2::Style := [Impulses]: f2::Grid := [20]: 
   f2::Color := RGB::Red:
   plot(f1, f2)

Plot options, which are explicitely set for a function primitive, are stored under the attribute options and can be read with the slot operator ::. The plot options for the first created object are:

>> f1::options
                     table(
                       RealValuesOnly = TRUE,
                       Discont = TRUE,
                       Grid = [100],
                       Color = [Flat, [0.0, 0.0, 1.0]]
                     )

These are default values of some plot options of two-dimensional function primitives, defined by the entry "defaultOptions" of the domain plot::Function2d:

>> plot::Function2d::defaultOptions
                     table(
                       RealValuesOnly = TRUE,
                       Discont = TRUE,
                       Grid = [100],
                       Color = [Flat, [1.0, 0.0, 0.0]]
                     )

When the plot data of a function primitive is created (calling the method "getPlotdata"), only those plot options are used that are contained in the table stored under the attribute options (here this is the table f1::options):

>> plot::Function2d::getPlotdata(f1)
      -- --               --    1  --
      |  |  Mode = Curve, |  x, --  |, x = [-5.0, -0.1413648217],
      |  |                |      2  |
      -- --               --    x  --
      
                                                       --
         Grid = [100], Color = [Flat, [0.0, 0.0, 1.0]]  |,
                                                        |
                                                       --
      
         --               --    1  --
         |  Mode = Curve, |  x, --  |, x = [0.1413648217, 5.0],
         |                |      2  |
         --               --    x  --
      
                                                                   --
         Title = "", Grid = [100], Color = [Flat, [0.0, 0.0, 1.0]]  |
                                                                    |
                                                                   --
      
         --
          |
          |
         --

This means that for any other available plot option not contained in the table f1::options, the default value is either set by plot::Scene, if the option also exists as a scene option, or it is internally set by the function plot2d when plotting the object.

This example also illustrates that plot::Function2d automatically determines discontinuities and splits the graph into two subgraphs around each discontinuity (these subgraphs are stored in the attribute objects, see above).

Here, the graph of 1/x^2 was splitted around 0 into two subgraphs. Thus, the plot structure in a plot2d conforming syntax consists of two objects of the mode Curve.

The determination of discontinuities can be controlled with the option Discont. If we set this option to FALSE, discontinuities are not determined. The plot structure of the function primitive then only consists of one object:

>> f1::Discont:= FALSE: plot::Function2d::getPlotdata(f1)
      -- --               --    1  --
      |  |  Mode = Curve, |  x, --  |, x = [-5.0, 5.0],
      |  |                |      2  |
      -- --               --    x  --
      
                                                       -- --
         Grid = [100], Color = [Flat, [0.0, 0.0, 1.0]]  |  |
                                                        |  |
                                                       -- --

Computation problems during the evaluation of the plot is the consequence here:

>> plot(f1)

The function primitive f2 contains the following options:

>> f2::options
                     table(
                       Style = [Impulses],
                       RealValuesOnly = TRUE,
                       Discont = TRUE,
                       Grid = [20],
                       Color = [Flat, [1.0, 0.0, 0.0]]
                     )

As you see, the option Style was added to this table, and the default value of the option Grid was replaced by the new value [20]. Use delete to remove plot options set for a curve primitive:

>> delete f2::options[Style]: f2::options
                     table(
                       RealValuesOnly = TRUE,
                       Discont = TRUE,
                       Grid = [20],
                       Color = [Flat, [1.0, 0.0, 0.0]]
                     )

You might wonder why the options RealValuesOnly and Discont are not contained in the plot structure returned by the method "getPlotdata". They are special options for objects of the domain plot::Function2d, used to determine the plot data of such an object. They are not accepted as valid options for curves plotted directly with plot2d.

Example 5

This example illustrates how to read and write attributes of function primitives (see the table of available attributes in ``Details'' above).

In the last example, we already used the attribute options, which stores plot options defined individually for a function primitive to override the corresponding default values set by MuPAD.

The attribute yrange holds the ``y-range'' of the function graph. Its value is either a range of the form y = ymin..ymax, or the identifier Automatic.

For example, if function is an object of plot::Function2d such as:

>> f := plot::Function2d(ln(x), x = 0..10)
                    plot::Function2d(ln(x), x = 0..10)

then f::yrange returns the default value of this attribute:

>> f::yrange
                                 Automatic

We plot this curve:

>> plot(f) 

Because the attribute yrange has the ``write'' property, you can change the value of this attribute as follows:

>> f::yrange := 0..1: plot(f)

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000