# Documentation

### This is machine translation

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

# `plot`::`VectorField2d`

2D vector field

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

## Syntax

```plot::VectorField2d(`[v1, v2]`, `x = xmin .. xmax`, `y = ymin .. ymax`, <`a = amin .. amax`>, `options`)
plot::VectorField2d(`v1`, `v2`, `x = xmin .. xmax`, `y = ymin .. ymax`, <`a = amin .. amax`>, `options`)
```

## Description

```plot::VectorField2d([v_1, v_2], x = `x_{min}`..`x_{max}`, y = `y_{min}`..`y_{max}`)``` represents a plot of the vector field defined by with (x, y) ∈ [xmin, xmax] ×[ymin, ymax].

A vector field is defined by a function . `plot::VectorField2d` displays a vector field by placing arrows at regular intervals with the arrow at (x, y) pointing in direction f(x, y).

The length of the arrows depend on |f(x, y)| and the setting of the attribute `ArrowLength`: By default, arrow lengths are proportional to the magnitude of f, but can be set to be of fixed length or to scale logarithmically.

The density of arrows placed can be controlled with the attributes `XMesh`, `YMesh`, and `Mesh`. See the examples below.

## Attributes

AttributePurposeDefault Value
`AffectViewingBox`influence of objects on the `ViewingBox` of a scene`TRUE`
`AntiAliased`antialiased lines and points?`TRUE`
`ArrowLength`scaling of arrows in a vector field`Proportional`
`Color`the main color`RGB::Blue`
`Frames`the number of frames in an animation`50`
`Legend`makes a legend entry
`LegendText`short explanatory text for legend
`LegendEntry`add this object to the legend?`FALSE`
`LineColor`color of lines`RGB::Blue`
`LineWidth`width of lines`0.35`
`LineColor2`color of lines`RGB::DeepPink`
`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[`11`, `11`]
`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
`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`
`TipAngle`opening angle of arrow heads`0.6283185307`
`TipStyle`presentation style of arrow heads`Open`
`TipLength`length of arrow heads`1.5`
`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
`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`
`XFunction`function for x values
`XMax`final value of parameter “x”
`XMesh`number of sample points for parameter “x”`11`
`XMin`initial value of parameter “x”
`XName`name of parameter “x”
`XRange`range of parameter “x”
`YFunction`function for y values
`YMax`final value of parameter “y”
`YMesh`number of sample points for parameter “y”`11`
`YMin`initial value of parameter “y”
`YName`name of parameter “y”
`YRange`range of parameter “y”

## Examples

### Example 1

We demonstrate a plot of the vector field v(x, y) = (1, sin(x) + cos(y)):

```field := plot::VectorField2d([1, sin(x) + cos(y)], x = 0..6, y = 0..2.5, Mesh = [31, 26]):```

It is the directional field associated with the ode . We insert curves representing numerical solutions of this ode into this plot. We use `numeric::odesolve2` to compute the numerical solutions for the initial values y(0) = 0.4, y(0.5) = 1.5, and y(1) = 1.2:

```f := (x, y) -> [sin(x) + cos(y[1])]: solution1 := numeric::odesolve2(f, 0, [0.4]): curve1 := plot::Function2d(solution1(x)[1], x = 0 .. 6, LineColor = RGB::Blue): solution2 := numeric::odesolve2(f, 0.5, [1.5]): curve2 := plot::Function2d(solution2(x)[1], x = 0.5 .. 6, LineColor = RGB::Black): solution3 := numeric::odesolve2(f, 1, [1.2]): curve3 := plot::Function2d(solution3(x)[1], x = 1 .. 6, LineColor = RGB::GreenDark):```

We plot the three objects in a single graphical scene:

`plot(field, curve1, curve2, curve3, GridVisible = TRUE):`

`delete field, curve1, curve2, curve3:`

### Example 2

Assume you want to plot an electrostatic potential field. The following routine generates the necessary formula in a format accepted by `plot::VectorField2d`:

```potentialE := proc(l) local p, x0, y0, f0, fx, fy, dist; begin fx := 0; fy := 0; for p in [args()] do [x0, y0, f0] := p; dist := sqrt((x-x0)^2 + (y-y0)^2); fx := fx + f0*(x-x0)/dist; fy := fy + f0*(y-y0)/dist; end_for; [fx, fy]; end_proc:```
```plot(plot::VectorField2d(potentialE([-1, -2, -1 ], [ 1, 3, 0.5], [ 2, -1, 0.5]), x = -3..3, y = -3..3, XMesh = 30, YMesh = 30)):```

### Example 3

Like most other objects, `plot::VectorField2d` can be animated by supplying an extra parameter:

```field := plot::VectorField2d([1, a*sin(x) + (a-1)*cos(y)], x = 0..6, y = 0..2.5, a=-1..1): text := plot::Text2d(a -> "a = ".stringlib::formatf(a, 2, 5), [2, -0.5], a = -1..1, HorizontalAlignment = Left): plot(field, text)```

`delete field, text:`

## Parameters

 `v1`, `v2` The x- and y-component of the vector field: arithmetical expressions in `x`, `y`, and, possibly, the animation parameter `a`. `v1`, `v2` are equivalent to the attributes `XFunction`, `YFunction`. `x`, `y` Identifiers. `x`, `y` are equivalent to the attributes `XName`, `YName`. `xmin .. xmax`, `ymin .. ymax` Real numerical values. `xmin` .. `xmax`, `ymin` .. `ymax` are equivalent to the attributes `XRange`, `YRange`, `XMin`, `XMax`, `YMin`, `YMax`. `a` Animation parameter, specified as `a```` = amin..amax```, where `amin` is the initial parameter value, and `amax` is the final parameter value.