field

A differential equation drawn as the directions it gives, and the solutions that follow them. field: x - y is a first-order equation y′=f(x,y)y' = f(x, y), drawn as a slope field of headless ticks; field(dx: y; dy: -x) is a system x′=…, y′=…x' = \ldots,\ y' = \ldots, drawn as a direction field of arrows — the phase plane. On the argand plane the one expression is f(z)f(z) and the field is the flow of z′=f(z)z' = f(z). Every arrow is the same length; the field's strength is its colour. Seeds in from: are integrated forward and back until the solution leaves the window, comes to rest or closes a loop, and the reader may drag them. x and y are the axes here, not parameters: only the letters beyond them get footer sliders.

fieldNode
Only withxyargandplane
The predator–prey arrows of the Lotka–Volterra equations, coloured by strength, circling the balance point at (2, 2).The predator–prey arrows of the Lotka–Volterra equations, coloured by strength, circling the balance point at (2, 2).

A field draws a differential equation: at each point of a grid, an arrow in the direction the equation gives there. Every arrow is the same length, so the direction is what you read, and the field's strength is its colour — a colour that is a single hue or a ramp, as a contour's is. The footer carries the key and reads off the strength under the cursor. density sets how many arrows run across the plot, 20 unless you say otherwise.

#Slopes and systems

field: x - y is a first-order equation, y′ = x − y. It is drawn as a slope field: short ticks without heads, since a slope has a steepness but no forward, and coloured by how steep it is. field(dx: y; dy: -x) is a system of two, x′ and y′, drawn as arrows. This is the phase plane, where every point is a state and the arrow says where the state goes next. Write one form or the other; both together are refused.

On the argand plane a field is one function of z: field: z^2 - 1 draws the flow of z′ = f(z), with the arrow at z pointing along f(z). The number line and the polar plane take no field.

x and y are the axes in a field's expressions, not parameters. Any other letter is a parameter, r included: dy: r * y * (1 - y) is logistic growth with a slider for its rate.

#Solutions

from starts solutions at points of the plane: from: (1, 0), (2.5, 0). Each is followed both ways in time until it leaves the window, comes to rest or closes a loop, and it is worked out again whenever a parameter moves. span: [0, 5] runs it over that stretch of time instead, forward only. The reader can drag a starting point, and the solution through it follows; draggable: false fixes them. arrows: false leaves only the solutions. solution-colour and solution-width style them.

The FitzHugh–Nagumo neuron as a direction field over voltage and recovery, with one orange solution settling onto the closed loop of a neuron firing repeatedly.The FitzHugh–Nagumo neuron as a direction field over voltage and recovery, with one orange solution settling onto the closed loop of a neuron firing repeatedly.
canvas.graph{
    field(
        dx: x - x^3 / 3 - y + 0.5
        dy: 0.08 * (x + 0.7 - 0.8 * y)
        from: (-1.2, -0.6)
    )
}(
    x-domain: [-2.5, 2.5]
    y-domain: [-1, 2]
    x-axis-label: $v$
    y-axis-label: $w$
)

#Drawing, tracing and flow

Inside a cue.draw, each solution is drawn in from its earliest time to its latest while the arrows fade in. A cue.trace can name the field as its path, path: #phase, and rides the first solution at the same pace, so a dot and the line it draws arrive together. flow: true sets dots moving along the field at its own speeds: they crawl where it is weak and race where it is strong. They stay still for a reader who has asked for reduced motion.


#Attributes

On any plane
expressionImplicitAnimatable
The slope y′=f(x,y)y' = f(x, y) on the xy plane, or f(z)f(z) on the argand plane. Written instead of dx and dy, never beside them.
field-expression
Also written: slope, f, exp, func, functionCan be written as shorthand: field:value
fromAnimatable
Where solutions start, each a pair in the plane's axes: from: (1, 0), (2.5, 0). A cue.trace naming the field rides the first one.
Also written: seeds, through
spanAnimatable
The time each solution runs over, its seed at 0: [0, 5] runs forward only. Absent, a solution runs both ways until it leaves the window, comes to rest or closes a loop.
Also written: t, time
densityAnimatable
How many arrows across the wider side of the plot; the grid is square.
Default20
arrowsAnimatable
Draw the grid of arrows. Off, only the solutions and the flow are drawn.
Defaulttrue
flowAnimatable
Dots carried along the field at its own speeds, continuously. Still for a reader who has asked for reduced motion.
Defaultfalse
draggable
Whether the reader may drag a seed; its solution is re-integrated as it moves.
Also written: drag
Defaulttrue
colourAnimatable
The arrows' paint by the field's strength: multicolour (the default) runs violet weak to red strong, temperature the blue → white → red ramp, a hue its own pale to deep. The footer's key prices the cursor at the strength under it.
blueredorangeyellowtealgreenpinkpurplegreyhex(…)rgb(…)multicolourtemperature
Also written: color
Defaultmulticolour
widthAnimatable
The arrows' stroke width.
Default1.25
opacityAnimatable
How heavy the arrows sit over the marks beneath them.
Default0.85
solution-colourAnimatable
The colour of the solutions, their seeds and the flowing dots.
bluelight-bluedark-blueredlight-reddark-redorangelight-orangedark-orangeyellowlight-yellowdark-yellowteallight-tealdark-tealgreenlight-greendark-greenpinklight-pinkdark-pinkpurplelight-purpledark-purplegreylight-greydark-greyneutralhex(…)rgb(…)
Also written: solution-color
Defaultorange
solution-widthAnimatable
The solutions' stroke width.
Default2
hiddenAnimatable
Declared but not drawn — animatable, so hidden: true !cue.to{false}(at: 2) is its reveal.
Defaultfalse
lock
A reader may not edit it on an editable graph.
Also written: locked
Defaultfalse
layerAnimatable
Paint order among the marks: a higher layer is drawn later, on top; equal or omitted, the marks stack in document order (later on top).
Only withxyplane
dxAnimatable
x′x' in a system of two, in x and y. Needs dy.
field-component
dyAnimatable
y′y' in a system of two, in x and y. Needs dx.
field-component

#Examples

The slope field of y′ = x − y as short headless ticks coloured by steepness, levelling out along the line y = x − 1.The slope field of y′ = x − y as short headless ticks coloured by steepness, levelling out along the line y = x − 1.
canvas.graph{
    field(slope: x - y)
}(
    x-domain: [-4, 4]
    y-domain: [-4, 4]
)
The phase plane of a damped pendulum in blue arrows, with two orange solutions spiralling into the rest point at the origin between the saddles at ±π.The phase plane of a damped pendulum in blue arrows, with two orange solutions spiralling into the rest point at the origin between the saddles at ±π.
canvas.graph{
    field(
        dx: y
        dy: -sin(x) - 0.3 * y
        from: (-2, 1), (2.5, -0.5)
        colour: blue
    )
}(
    x-domain: [-7, 7]
    y-domain: [-3, 3]
    x-axis-label: $\theta$
    y-axis-label: $\theta'$
)
The flow of z′ = z² − 1 on the argand plane, its arrows on the blue-to-red temperature ramp, streaming out of +1 and into −1.The flow of z′ = z² − 1 on the argand plane, its arrows on the blue-to-red temperature ramp, streaming out of +1 and into −1.
canvas.graph:argand{
    field(f: z^2 - 1; colour: temperature)
}(
    re-domain: [-2, 2]
    im-domain: [-2, 2]
)

Last updated