Documentation Center

  • Trial Software
  • Product Updates

plot::VectorField2d

2D vector field

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

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
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
AntiAliasedantialiased lines and points?TRUE
ArrowLengthscaling of arrows in a vector fieldProportional
Colorthe main colorRGB::Blue
Framesthe number of frames in an animation50
Legendmakes a legend entry 
LegendTextshort explanatory text for legend 
LegendEntryadd this object to the legend?FALSE
LineColorcolor of linesRGB::Blue
LineWidthwidth of lines0.35
LineColor2color of linesRGB::DeepPink
LineColorTypeline coloring typesFlat
LineColorFunctionfunctional line coloring 
LineColorDirectionthe direction of color transitions on lines[0, 1]
LineColorDirectionXx-component of the direction of color transitions on lines0
LineColorDirectionYy-component of the direction of color transitions on lines1
Meshnumber of sample points[11, 11]
Namethe name of a plot object (for browser and legend) 
ParameterEndend value of the animation parameter 
ParameterNamename of the animation parameter 
ParameterBegininitial value of the animation parameter 
ParameterRangerange of the animation parameter 
TimeEndend time of the animation10.0
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0
TipAngleopening angle of arrow heads0.6283185307
TipStylepresentation style of arrow headsOpen
TipLengthlength of arrow heads1.5
Titleobject title 
TitleFontfont of object titles[" sans-serif ", 11]
TitlePositionposition of object titles 
TitleAlignmenthorizontal alignment of titles w.r.t. their coordinatesCenter
TitlePositionXposition of object titles, x component 
TitlePositionYposition of object titles, y component 
VisiblevisibilityTRUE
VisibleAfterobject visible after this time value 
VisibleBeforeobject visible until this time value 
VisibleFromToobject visible during this time range 
VisibleAfterEndobject visible after its animation time ended?TRUE
VisibleBeforeBeginobject visible before its animation time starts?TRUE
XFunctionfunction for x values 
XMaxfinal value of parameter "x" 
XMeshnumber of sample points for parameter "x"11
XMininitial value of parameter "x" 
XNamename of parameter "x" 
XRangerange of parameter "x" 
YFunctionfunction for y values 
YMaxfinal value of parameter "y" 
YMeshnumber of sample points for parameter "y"11
YMininitial value of parameter "y" 
YNamename of parameter "y" 
YRangerange 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.

See Also

MuPAD Functions

MuPAD Graphical Primitives

Was this topic helpful?