Skip to Main Content Skip to Search
Product Documentation

plot::Function3d3D function graphs

plot::Function3d creates the 3D graph of a function in 2 variables.

→ Examples

Calls:

plot::Function3d(f, Options)

plot::Function3d(f, x = `x_{min}` .. `x_{max}`, y = `y_{min}` .. `y_{max}`, <a = amin .. amax>, Options)

Parameters:

f

the function: an arithmetical expression or a piecewise object in the independent variables x, y and the animation parameter a. Alternatively, a MuPAD procedure that accepts 2 input parameter x, y or 3 input parameters x, y, a and returns a numerical value when the input parameters are numerical. 
f is equivalent to the attribute Function.

x

the first independent variable: an identifier or an indexed identifier
x is equivalent to the attribute XName.

`x_{min}` .. `x_{max}`

the plot range in x direction: `x_{min}`, `x_{max}` must be numerical real values or expressions of the animation parameter a. If not specified, the default range x = -5 .. 5 is used. 
`x_{min}` .. `x_{max}` is equivalent to the attributes XRange, XMin, XMax.

y

the second independent variable: an identifier or an indexed identifier
y is equivalent to the attribute YName.

`y_{min}` .. `y_{max}`

the plot range in y direction: `y_{min}`, `y_{max}` must be numerical real values or expressions of the animation parameter a. If not specified, the default range y = -5 .. 5 is used. 
`y_{min}` .. `y_{max}` is equivalent to the attributes YRange, YMin, YMax.

See Also:

plot, plot::copy, plot::Function2d, plot::Surface, plotfunc2d, plotfunc3d

Details:

Example 1

The following call returns an object representing the graph of the function sin(x^2 + y^2) over the region (-2 <= x) <= 2, (-2 <= y) <= 2:

g := plot::Function3d(sin(x^2 + y^2), x = -2..2, y = -2..2)

plot::Function3d(sin(x^2 + y^2), x = -2..2, y = -2..2)

Call plot to plot the graph:

plot(g)

MuPAD graphics

Functions can also be specified by piecewise objects or procedures:

f := piecewise([x < y, 0], [x >= y, (x - y)^2]):
plot(plot::Function3d(f, x = -2 .. 4, y = -1 .. 3))

MuPAD graphics

f := proc(x, y)
begin
  if x + y^2 + 2*y < 0 then
     0
  else
     x + y^2 + 2*y
  end_if:
end_proc:
plot(plot::Function3d(f, x = -3 .. 2, y = -2 .. 2))

MuPAD graphics

delete g, f

Example 2

We plot a function with singularities:

f := plot::Function3d(x/y + y/x, x = -1 .. 1, y = - 1 .. 1):
plot(f)

MuPAD graphics

We specify an explicit viewing range for the z direction:

plot(f, ViewingBoxZRange = -20 .. 20)

MuPAD graphics

delete f

Example 3

We generate an animation of a parametrized function:

plot(plot::Function3d(sin((x - a)^2 + y^2),
                      x = -2 .. 2, y = -2 .. 2, a = 0 .. 5))

MuPAD graphicsimage

Example 4

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::Function3d(besselJ(0, sqrt(x^2 + y^2)),
                      x = -20 .. 20, y = -20 .. 20))

MuPAD graphics

We increase the number of mesh points. Here, we use XSubmesh and YSubmesh to place 2 additional points in each direction between each pair of neighboring points of the default mesh. This increases the runtime by a factor of 9:

plot(plot::Function3d(besselJ(0, sqrt(x^2 + y^2)),
                      x = -20 .. 20, y = -20 .. 20,
                      Submesh = [2, 2]))

MuPAD graphics

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

plot(plot::Function3d(besselJ(0, sqrt(x^2 + y^2)),
                      x = -20 .. 20, y = -20 .. 20,
                      AdaptiveMesh = 2))

MuPAD graphics

Example 5

By default, the parameter lines of a function graph are “switched on”:

plot(plot::Function3d(x^2 + y^2, x = 0 .. 1, y = 0 .. 1))

MuPAD graphics

The parameter lines are “switched off” by setting XLinesVisible, YLinesVisible:

plot(plot::Function3d(x^2 + y^2, x = 0 .. 1, y = 0 .. 1,
                      XLinesVisible = FALSE,
                      YLinesVisible = FALSE))

MuPAD graphics

The number of parameter lines are determined by the Mesh attributes:

plot(plot::Function3d(x^2 + y^2, x = 0 .. 1, y = 0 .. 1,
                      Mesh = [5, 12]))

MuPAD graphics

When the mesh is refined via the Submesh attributes, the numerical approximation of the surface becomes smoother. However, the number of parameter lines is not increased:

plot(plot::Function3d(x^2 + y^2, x = 0 .. 1, y = 0 .. 1,
                      Mesh = [5, 12],
                      XSubmesh = 1, YSubmesh = 2))

MuPAD graphics

Example 6

Functions need not be defined over the whole parameter range:

plot(plot::Function3d(sqrt(1-x^2-y^2), x=-1..1, y=-1..1))

MuPAD graphics

plot(plot::Function3d(sqrt(sin(x)+cos(y))))

MuPAD graphics

This makes for an easy way of plotting a function over a non-rectangular area:

chi := piecewise([x^2 < abs(y), 1])

piecewise([x^2 < abs(y), 1])

plot(plot::Function3d(chi*sin(x+cos(y))),
     CameraDirection=[-1,0,0.5])

MuPAD graphics

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS