# Documentation

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```gradient(`f`, `x`)
gradient(`f`, `x`, `ogCoord`, <`c`>)
```

## Description

`gradient(f, x)` computes the vector gradient of the scalar function with respect to in Cartesian coordinates. This is the vector .

`ogCoord` can be the name of a three-dimensional orthogonal coordinate system predefined in the table `linalg::ogCoordTab`. See Example 2.

Alternatively, `ogCoord` can be a list of vector of algebraic expressions representing the scale factors of the coordinate system. See example Example 3. For details, see the description of the `Scales` option on the `linalg::ogCoordTab` page.

## Examples

### Example 1

Compute the vector gradient of the scalar function f(x, y) = x2 + y in Cartesian coordinates:

```delete x, y: gradient(x^2 + y, [x, y])```

### Example 2

Compute the gradient of the function f(r, ϕ, z) = rcos(ϕ) z (0 ≤ ϕ < 2π) in cylindrical coordinates:

```delete r, z, phi: gradient(r*cos(phi)*z, [r, phi, z], Cylindrical)```

### Example 3

Compute the gradient of the function f(r, ϕ, θ) = rsin(ϕ) cos(θ) in spherical coordinates given by

with 0 ≤ θ ≤ π, 0 ≤ ϕ < 2 π.

The vectors

form an orthogonal system in spherical coordinates.

The scaling factors of the corresponding coordinate transformation (see `linalg::ogCoordTab`) are: , which we use in the following example to compute the gradient of the function f in spherical coordinates:

```delete r, Theta, phi: gradient(r*sin(phi)*cos(Theta), [r, Theta, phi], [1, r, r*sin(Theta)])```

The spherical coordinates are already defined in `linalg::ogCoordTab`. The last result can also be achieved with the input ```gradient(r*sin(phi)*cos(Theta), [r, Theta, phi], Spherical[RightHanded])```:

```gradient(r*sin(phi)*cos(Theta), [r, Theta, phi], Spherical[RightHanded])```

## Parameters

 `f` An arithmetical expression in the variables given in `x` `x` A list of (indexed) identifiers `ogCoord` The name of a 3 dimensional orthogonal coordinate system predefined in the table `linalg::ogCoordTab`, or a list of algebraic expressions representing the scale factors of an orthogonal coordinate system. `c` The parameter of the coordinate systems EllipticCylindrical and Torus, respectively: an arithmetical expression. The default value is `c` = 1.

## Return Values

Column vector of the domain `Dom::Matrix``()`.