# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# `Function`, `XFunction`, `YFunction`, `ZFunction`

Function expression or procedure

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Value Summary

 `Function`, `XFunction`, `YFunction`, `ZFunction` Mandatory MuPAD® expression

## Description

`Function`, `XFunction`, `YFunction`, `ZFunction` correspond to function expressions or procedures in various plot objects given by a mathematical function.

The attribute `Function` is used for graphs of functions in 2D and 3D, implicit plots, conformal plots etc. which are characterized by a single function.

The attributes `XFunction` etc. refer to the parametrization of the x, y or z-coordinate of parametrized curves and surfaces. In vector field plots they correspond to the components of the vector field.

When defining a graphical primitive such as a function plot, the mathematical expression defining the function is passed directly to the plot routine generating this object. E.g., one calls ```plot::Function2d(x*sin(x), x = -5 .. 5)``` to define the graph of f(x) = xsin(x). Internally, the attribute `Function = x*sin(x)` is associated with the graphical object.

Wherever function expressions are expected, also `piecewise` objects or MuPAD procedures can be used. E.g., the calls `plot::Function2d(sin(x), x = 0..PI)` and `plot::Function2d(x -> sin(x), x = 0..PI)` are equivalent and associate the attributes `Function = sin(x)` or ```Function = x -> sin(x)```, respectively, with the plot objects.

## Examples

### Example 1

We define an object of type `plot::Function2d` representing the graph of f(x) = xsin(x):

```f := plot::Function2d(x*sin(x), x = -4 .. 4): plot(f)```

Internally, the expression defining the function is turned into the attribute `Function = x*sin(x)`. It is accessible via a corresponding `slot` of the object:

`f::Function`

One can change the object by reassigning a new value to this attribute:

```f::Function := 1/x: plot(f):```

`delete f:`

### Example 2

For implicit plots as produced by `plot::Implicit2d` and `plot::Implicit3d`, the attribute `Function` refers to the function whose zero set is to be plotted:

`p := plot::Implicit2d(y*sin(x) - x*cos(y), x=-5..5, y=-5..5):`

Internally, the expression defining the function is turned into the attribute `Function = y*sin(x) - x*cos(y)`. It is accessible via a corresponding `slot` of the object:

`p::Function`

`delete p:`

### Example 3

For parametrized curves and surfaces, the attributes `XFunction`, `YFunction` etc. correspond to the parametrization of the coordinates x, y etc:

```c2 := plot::Curve2d([u*cos(u), u*sin(u)], u = 0..5*PI): c2::XFunction, c2::YFunction```

```c3 := plot::Curve3d([u*cos(u), u*sin(u), u^2], u = 0..5*PI): c3::XFunction, c3::YFunction, c3::ZFunction```

```s := plot::Surface([u*cos(v), u*sin(v), u^2*sin(2*v)], u = 0..1, v = 0..2*PI): s::XFunction, s::YFunction, s::ZFunction```

`delete c2, c3, s:`

### Example 4

Wherever a function expression is expected, also a `piecewise` object or a procedure can be used:

```f1 := piecewise([x < 0, 0], [x >= 0, x]): f2 := proc(x) begin if x < 0 then 1 else 1 - x^2/2 end_if; end_proc: F1 := plot::Function2d(f1, x = -1..PI/2): F2 := plot::Function2d(f2, x = -1..PI/2): F1::Function, F2::Function```

`plot(F1, F2)`

`delete f1, f2, F1, F2:`