Skip to main content
\(\require{cancel}\newcommand{\domain}[1]{\operatorname{Dom}(#1)} \newcommand{\range}[1]{\operatorname{Range}(#1)} \newcommand{\linearspan}{\operatorname{span}} \newcommand{\abs}[1]{\lvert #1 \rvert} \newcommand{\set}[2]{\left\{ #1 \: \middle\vert \: #2 \right\}} \renewcommand{\vec}[1]{\mathbf{#1}} \newcommand{\Z}{\mathbb{Z}} \newcommand{\Q}{\mathbb{Q}} \newcommand{\R}{\mathbb{R}} \DeclareMathOperator{\Lapl}{\mathcal{L}} \newcommand{\La}[1]{\Lapl \left\{ #1 \right\}} \newcommand{\invLa}[1]{\Lapl^{-1}\left\{ #1 \right\}} \newcommand{\intbyparts}[4]{\begin{tabular}{|rl|rl|}\hline $u$ \amp $#1$ \amp $dv$ \amp $#2$ \\ \hline $du$ \amp $#3$ \amp $v$ \amp $#4$ \\ \hline \end{tabular}} \newcommand{\identity}{\mathrm{id}} \newcommand{\notdivide}{{\not{\mid}}} \newcommand{\notsubset}{\not\subset} \newcommand{\swap}{\mathrm{swap}} \newcommand{\Null}{\operatorname{Null}} \newcommand{\half}{\text{ \nicefrac{1}{2}}} \newcommand{\lt}{<} \newcommand{\gt}{>} \newcommand{\amp}{&} \)

Section2.4Graphical Solution Methods

Slope Fields and Graphing Approximate Solutions

A simple, graphical method for approximating solution curves exists for first--order differential equations. This method of approximating solutions uses a special plot called a slope field or a direction field plot. Specifically, if we can write a differential equation in the form: \begin{equation} \boxed{\dfrac{dy}{dx} = f(x,y)} \label{eqn-gen-first-order}\tag{2.4.1} \end{equation} then we can approximate solutions via the slope field plot. So how does one construct such a plot?

The answer lies in noticing that the right hand side of equation (2.4.1) is a function of points in the \(xy\) plane which result in the left hand side which is exactly the instantaneous slope of \(y(x)\text{,}\) the solution function we seek! If we know the slope of a function at every point on the \(x\)–axis, then we can graphically reconstruct the solution function \(y(x)\text{.}\)

Creating a slope field plot is normally done via software on a computer. The basic algorithm that a computer employs to do this is essentially the following:

  1. Divide the \(xy\) plane evenly into a grid of squares.

  2. For each point \((x_i, y_i)\) in the grid do the following:

    1. compute the slope, \(dy/dx = f(x_i, y_i)\text{.}\)

    2. Draw a small bar centered on the point \((x_i, y_i)\) with slope computed above. (Each bar should be of equal length and short enough so that they do not overlap.)

Figure 2.4.1 demonstrates the output of the above algorithm for the differential equation, \(y' = \tfrac{y}{x^2+1}\text{.}\)

<<SVG image is unavailable, or your browser cannot render it>>

Figure2.4.1Slope field plot for the equation: \(y' = \frac{y}{x^2+1}\)

SubsectionSlope Fields with Sage

As you can imagine the algorithm given above is rather tedious to perform by hand. Luckily, there are several software tools which can do the work for us. This section demonstrates Sage code for generating slope field plots.

The first Sage cell below demonstrates how to create a slopefield for the equation: \begin{equation} \frac{dy}{dx} = 3x^2, \label{men-21}\tag{2.4.2} \end{equation} which has solution \(y = x^3\text{.}\) The slopefield helps you to visualize solution curves.

The idea of a slope field plot becomes much clearer if we plot solution curves along with the slope bars. Of course, usually we will use slope field plots to visualize solutions when we can't solve the differential equation, but first we will demonstrate how to create a slopefield plot with several solution curves when we know the exact general solution.

For example, recall the population model with its accompanying general solution, \begin{equation} \frac{dP}{dt} = kP \qquad P(t) = P_0 e^{kt}. \label{men-22}\tag{2.4.3} \end{equation} It is important to note that no software can plot general solutions, because in order to plot points, the computer must be able to generate coordinate pairs. This can only be done if we specify values for the constants \(P_0\) and \(k\text{.}\)

Sometimes one solution curve plotted against the slope field will suffice. In this case, the desolve_rk4 command will generate both the slope field plot and one approximate solution curve. The code below graphically approximates the linear equation \begin{equation} \frac{dy}{dx} = -y + \cos x \label{men-23}\tag{2.4.4} \end{equation} The approximate solution curve is generated via the 4th order Runge–Kutta algorithm. We will see how this numerical approximation technique works in section 3.2. The code below also demonstrates how to continue a command onto the next line by appending the “\” character to the end of the line.

Finally, we will most often want to combine a slope field plot with multiple numerically approximated solution curves. The following code demonstrates this for the differential equation, \begin{equation} \frac{dy}{dx} = \cos(xy), \label{men-24}\tag{2.4.5} \end{equation} which has no solution expressible in terms of elementary functions. The following code generates the slope field plot and then combines that with the ouput from calling desolve_rk4 repeatedly.

SubsectionThe Isocline Method

The simple algorithm given above is fine for a computer program, but is very hard for a human to use in practice. However there is a simpler algorithm which can be done by hand with pencil and graph paper. The main idea is to find the isoclines in the slopefield, and plot regularly spaced, identical slope bars over the entire length of the isocline.

Definition2.4.2

An isocline is a line or curve upon which the slope is constant.

Suppose we wish to create a slope--field plot for the differential equation \begin{equation*} \frac{dy}{dx} = x-y = f(x,y). \end{equation*} The method involves two steps. First, we create a table. Each row in the table corresponds to one isocline. Second, for each row in the table we graph the corresponding isocline and decorate it with regularly spaced bars, all of which have equal slope. The slope corresponds to the value in the first column of the table.

Table contains the data for seven isoclines, one for each integer slope value from \(-3, \ldots, 3\text{.}\) We must graph each equation of a line from the third column, and decorate it with regularly spaced bars where the slope comes from the first column.

Slope Isocline
\(m\) \(=\) \(f(x,y)\) \(\quad \Longrightarrow \quad\) \(y\) \(=\) \(h(x)\)
\(-3\) \(=\) \(x-y\) \(\quad \Longrightarrow \quad\) \(y\) \(=\) \(x+3\)
\(-2\) \(=\) \(x-y\) \(\quad \Longrightarrow \quad\) \(y\) \(=\) \(x+2\)
\(-1\) \(=\) \(x-y\) \(\quad \Longrightarrow \quad\) \(y\) \(=\) \(x+1\)
\(0\) \(=\) \(x-y\) \(\quad \Longrightarrow \quad\) \(y\) \(=\) \(x+0\)
\(1\) \(=\) \(x-y\) \(\quad \Longrightarrow \quad\) \(y\) \(=\) \(x-1\)
\(3\) \(=\) \(x-y\) \(\quad \Longrightarrow \quad\) \(y\) \(=\) \(x-3\)

SubsectionExercises

1

Use the isocline method to create a slope field plot by hand for the following first order differential equation. \begin{equation*} \frac{dy}{dx} = x+y \end{equation*}

2

Use the isocline method to create a slope field plot by hand for the following first order differential equation. \begin{equation*} \frac{dy}{dx} = y-x+1 \end{equation*}

3

Use Sage to create a slope field for the nonlinear equation: \begin{equation*} \frac{dy}{dx} = \cos(xy) \end{equation*} with boundaries \(-3 \lt x \lt 3\) and \(-3 \lt y \lt 3\text{.}\)

4

Use Sage to create a slope field for the nonlinear equation: \begin{equation*} \frac{dy}{dx} = \ln(1+y^2) \end{equation*} with boundaries \(-3 \lt x \lt 3\) and \(-3 \lt y \lt 3\text{.}\)

5

Use Sage to create a slope field plot for the nonlinear equation: \begin{equation*} \frac{dy}{dx} = y^2\cos(x) \end{equation*} with boundaries \(-\pi \lt x \lt \pi\) and \(-1 \lt y \lt 1\text{.}\)

Solution
6

There was a typo in this problem! The \(y\) bounds have been changed: \begin{equation*} \text{from } -3 \lt y \lt 3 \quad \text{to} \quad -30 \lt y \lt 30. \end{equation*}

Find the general solution to the given linear equation. Use Sage to create a slope field plot for the equation: \begin{equation*} \frac{dy}{dx} = y + \cos(x) \end{equation*} with boundaries \(-3 \lt x \lt 3\) and \(-30 \lt y \lt 30\text{.}\) On the same plot axes, plot particular solutions which correspond with the initial conditions \(y(0)=1\) and \(y(0)=-1\text{.}\)