Slope field

From HandWiki
Revision as of 21:27, 6 February 2024 by Dennis Ross (talk | contribs) (change)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Short description: Visual representation of solutions to a differential equation
The slope field of [math]\displaystyle{ \frac{dy}{dx}=x^{2}-x-2 }[/math], with the blue, red, and turquoise lines being [math]\displaystyle{ \frac{x^{3}}{3}-\frac{x^{2}}{2}-2x+4 }[/math], [math]\displaystyle{ \frac{x^{3}}{3}-\frac{x^{2}}{2}-2x }[/math], and [math]\displaystyle{ \frac{x^{3}}{3}-\frac{x^{2}}{2}-2x-4 }[/math], respectively.

A slope field (also called a direction field[1]) is a graphical representation of the solutions to a first-order differential equation[2] of a scalar function. Solutions to a slope field are functions drawn as solid curves. A slope field shows the slope of a differential equation at certain vertical and horizontal intervals on the x-y plane, and can be used to determine the approximate tangent slope at a point on a curve, where the curve is some solution to the differential equation.

Definition

Standard case

The slope field can be defined for the following type of differential equations

[math]\displaystyle{ y' = f(x, y), }[/math]

which can be interpreted geometrically as giving the slope of the tangent to the graph of the differential equation's solution (integral curve) at each point (x, y) as a function of the point coordinates.[3]

It can be viewed as a creative way to plot a real-valued function of two real variables [math]\displaystyle{ f(x,y) }[/math] as a planar picture. Specifically, for a given pair [math]\displaystyle{ x,y }[/math], a vector with the components [math]\displaystyle{ [1, f(x,y)] }[/math] is drawn at the point [math]\displaystyle{ x,y }[/math] on the [math]\displaystyle{ x,y }[/math]-plane. Sometimes, the vector [math]\displaystyle{ [1, f(x,y)] }[/math] is normalized to make the plot better looking for a human eye. A set of pairs [math]\displaystyle{ x,y }[/math] making a rectangular grid is typically used for the drawing.

An isocline (a series of lines with the same slope) is often used to supplement the slope field. In an equation of the form [math]\displaystyle{ y'=f(x,y) }[/math], the isocline is a line in the [math]\displaystyle{ x,y }[/math]-plane obtained by setting [math]\displaystyle{ f(x,y) }[/math] equal to a constant.

General case of a system of differential equations

Given a system of differential equations,

[math]\displaystyle{ \begin{align} \frac{dx_1}{dt}&=f_1(t, x_1, x_2, \ldots, x_n) \\ \frac{dx_2}{dt}&=f_2(t, x_1, x_2, \ldots, x_n) \\ &\;\;\vdots \\ \frac{dx_n}{dt}&=f_n(t, x_1, x_2, \ldots, x_n) \end{align} }[/math]

the slope field is an array of slope marks in the phase space (in any number of dimensions depending on the number of relevant variables; for example, two in the case of a first-order linear ODE, as seen to the right). Each slope mark is centered at a point [math]\displaystyle{ (t,x_1,x_2,\ldots,x_n) }[/math] and is parallel to the vector

[math]\displaystyle{ \begin{pmatrix} 1 \\ f_1(t,x_1,x_2,\ldots,x_n) \\ f_2(t,x_1,x_2,\ldots,x_n) \\ \vdots \\ f_n(t,x_1,x_2,\ldots,x_n) \end{pmatrix}. }[/math]

The number, position, and length of the slope marks can be arbitrary. The positions are usually chosen such that the points [math]\displaystyle{ (t,x_1,x_2,\ldots,x_n) }[/math] make a uniform grid. The standard case, described above, represents [math]\displaystyle{ n=1 }[/math]. The general case of the slope field for systems of differential equations is not easy to visualize for [math]\displaystyle{ n\gt 2 }[/math].

General application

With computers, complicated slope fields can be quickly made without tedium, and so an only recently practical application is to use them merely to get the feel for what a solution should be before an explicit general solution is sought. Of course, computers can also just solve for one, if it exists.

If there is no explicit general solution, computers can use slope fields (even if they aren’t shown) to numerically find graphical solutions. Examples of such routines are Euler's method, or better, the Runge–Kutta methods.

Software for plotting slope fields

Different software packages can plot slope fields.

Direction field code in GNU Octave/MATLAB

funn = @(x, y)y-x;                             % function f(x, y) = y-x
[x, y] = meshgrid(-5:0.5:5);                   % intervals for x and y
slopes = funn(x, y);                           % matrix of slope values
dy = slopes ./ sqrt(1 + slopes.^2);            % normalize the line element...
dx = ones(length(dy)) ./ sqrt(1 + slopes.^2);  % ...magnitudes for dy and dx
h = quiver(x, y, dx, dy, 0.5);                 % plot the direction field
set(h, "maxheadsize", 0.1);                    % alter head size

Example code for Maxima

/* field for y'=xy (click on a point to get an integral curve). Plotdf requires Xmaxima  */
plotdf( x*y, [x,-2,2], [y,-2,2]);

Example code for Mathematica

(* field for y'=xy *)
VectorPlot[{1,x*y-5x},{x,-2,2},{y,-2,2}]

Example code for SageMath[4]

var('x,y')
plot_slope_field(x*y, (x,-2,2), (y,-2,2))

Examples

See also

References

  • Blanchard, Paul; Devaney, Robert L.; and Hall, Glen R. (2002). Differential Equations (2nd ed.). Brooks/Cole: Thompson Learning. ISBN:0-534-38514-1

External links