maths.freeCalculus › 4. Introduction to Differential Equations › Direction Fields and Numerical Methods

Direction Fields and Numerical Methods

Draw the direction field for a given first-order differential equation.

Creating Direction Fields

Direction fields (also called slope fields) are useful for investigating first-order differential equations. In particular, we consider a first-order differential equation of the form

\[y'=f(x,y).\]

An applied example of this type of differential equation appears in Newton’s law of cooling, which we will solve explicitly later in this chapter. First, though, let us create a direction field for the differential equation

\[{T}^{'}(t)=-0.4(T-72).\]

Here \(T(t)\) represents the temperature (in degrees Fahrenheit) of an object at time \(t,\) and the ambient temperature is \(72\text{^{\circ}}\text{F}\text{.}\) shows the direction field for this equation.

The idea behind a direction field is the fact that the derivative of a function evaluated at a given point is the slope of the tangent line to the graph of that function at the same point. Other examples of differential equations for which we can create a direction field include

\[\begin{array}{l}y'=3x+2y-4 \\ y'={x}^{2}-{y}^{2} \\ y'=\frac{2x+4}{y-2}.\end{array}\]

To create a direction field, we start with the first equation: \(y'=3x+2y-4.\) We let \(({x}_{0},{y}_{0})\) be any ordered pair, and we substitute these numbers into the right-hand side of the differential equation. For example, if we choose \(x=1\ \text{and}\ y=2,\) substituting into the right-hand side of the differential equation yields

\[\begin{array}{ll}{y}^{'} & =3x+2y-4 \\ & =3(1)+2(2)-4=3.\end{array}\]

This tells us that if a solution to the differential equation \(y'=3x+2y-4\) passes through the point \((1,2),\) then the slope of the solution at that point must equal \(3.\) To start creating the direction field, we put a short line segment at the point \((1,2)\) having slope \(3.\) We can do this for any point in the domain of the function \(f(x,y)=3x+2y-4,\) which consists of all ordered pairs \((x,y)\) in \({ℝ}^{2}.\) Therefore any point in the Cartesian plane has a slope associated with it, assuming that a solution to the differential equation passes through that point. The direction field for the differential equation \({y}^{'}=3x+2y-4\) is shown in .

We can generate a direction field of this type for any differential equation of the form \(y'=f(x,y).\)

Using Direction Fields

We can use a direction field to predict the behavior of solutions to a differential equation without knowing the actual solution. For example, the direction field in serves as a guide to the behavior of solutions to the differential equation \(y'=3x+2y-4.\)

To use a direction field, we start by choosing any point in the field. The line segment at that point serves as a signpost telling us what direction to go from there. For example, if a solution to the differential equation passes through the point \((0,1),\) then the slope of the solution passing through that point is given by \(y'=3(0)+2(1)-4=-2.\) Now let \(x\) increase slightly, say to \(x=0.1.\) Using the method of linear approximations gives a formula for the approximate value of \(y\) for \(x=0.1.\) In particular,

\[\begin{array}{ll}L(x) & ={y}_{0}+{f}^{'}({x}_{0})(x-{x}_{0}) \\ & =1-2(x-0) \\ & =1-2x.\end{array}\]

Substituting \(x=0.1\) into \(L(x)\) gives an approximate \(y\) value of \(0.8.\)

At this point the slope of the solution changes (again according to the differential equation). We can keep progressing, recalculating the slope of the solution as we take small steps to the right, and watching the behavior of the solution. shows a graph of the solution passing through the point \((0,1).\)

The curve is the graph of the solution to the initial-value problem

\[y'=3x+2y-4,\ y(0)=1.\]

This curve is called a solution curve passing through the point \((0,1).\) The exact solution to this initial-value problem is

\[y=-\frac{3}{2}x+\frac{5}{4}-\frac{1}{4}{e}^{2x},\]

and the graph of this solution is identical to the curve in .

\[\begin{array}{ll}(x-3)({y}^{2}-4) & =(x-3)((-2{)}^{2}-4) \\ & =(x-3)(0) \\ & =0 \\ & =y'.\end{array}\]

Condensed — the full section is in OpenStax Calculus Volume 2.

Euler’s Method

Consider the initial-value problem

\[{y}^{'}=2x-3,\ y(0)=3.\]

Integrating both sides of the differential equation gives \(y={x}^{2}-3x+C,\) and solving for \(C\) yields the particular solution \(y={x}^{2}-3x+3.\) The solution for this initial-value problem appears as the parabola in .

The red graph consists of line segments that approximate the solution to the initial-value problem. The graph starts at the same initial value of \((0,3).\) Then the slope of the solution at any point is determined by the right-hand side of the differential equation, and the length of the line segment is determined by increasing the \(x\) value by \(0.5\) each time (the step size). This approach is the basis of Euler’s Method.

Before we state Euler’s Method as a theorem, let’s consider another initial-value problem:

\[{y}^{'}={x}^{2}-{y}^{2},\ y(-1)=2.\]

The idea behind direction fields can also be applied to this problem to study the behavior of its solution. For example, at the point \((-1,2),\) the slope of the solution is given by \(y'={(-1)}^{2}-{2}^{2}=-3,\) so the slope of the tangent line to the solution at that point is also equal to \(-3.\) Now we define \({x}_{0}=-1\) and \({y}_{0}=2.\) Since the slope of the solution at this point is equal to \(-3,\) we can use the method of linear approximation to approximate \(y\) near \((-1,2).\)

\[L(x)={y}_{0}+{f}^{'}({x}_{0})(x-{x}_{0}).\]

Here \({x}_{0}=-1,{y}_{0}=2,\) and \({f}^{'}({x}_{0})=-3,\) so the linear approximation becomes

\[\begin{array}{ll}L(x) & =2-3(x-(-1)) \\ & =2-3x-3 \\ & =-3x-1.\end{array}\]

Now we choose a step size. The step size is a small value, typically \(0.1\) or less, that serves as an increment for \(x;\) it is represented by the variable \(h.\) In our example, let \(h=0.1.\) Incrementing \({x}_{0}\) by \(h\) gives our next \(x\) value:

\[{x}_{1}={x}_{0}+h=-1+0.1=-0.9.\]\[\begin{array}{ll}{y}_{1} & =L({x}_{1}) \\ & =-3(-0.9)-1 \\ & =1.7.\end{array}\]\[\begin{array}{ll}L(x) & ={y}_{1}+{f}^{'}({x}_{1})(x-{x}_{1}) \\ & =1.7-2.08(x-(-0.9)) \\ & =1.7-2.08x-1.872 \\ & =-2.08x-0.172.\end{array}\]\[\begin{array}{ll}{y}_{2} & =L({x}_{2}) \\ & =-2.08{x}_{2}-0.172 \\ & =-2.08(-0.8)-0.172 \\ & =1.492.\end{array}\]
\(n\)\(0\)\(1\)\(2\)\(3\)\(4\)\(5\)
\({x}_{n}\)\(-1\)\(-0.9\)\(-0.8\)\(-0.7\)\(-0.6\)\(-0.5\)
\({y}_{n}\)\(2\)\(1.7\)\(1.492\)\(1.3334\)\(1.2046\)\(1.0955\)
\(n\)\(6\)\(7\)\(8\)\(9\)\(10\)
\({x}_{n}\)\(-0.4\)\(-0.3\)\(-0.2\)\(-0.1\)\(0\)
\({y}_{n}\)\(1.0004\)\(1.9164\)\(1.8414\)\(1.7746\)\(1.7156\)

Condensed — the full section is in OpenStax Calculus Volume 2.

Key Concepts

  • A direction field is a mathematical object used to graphically represent solutions to a first-order differential equation.
  • Euler’s Method is a numerical technique that can be used to approximate solutions to a differential equation.

Key Equations

Euler’s Method\(\begin{array}{l}{x}_{n}={x}_{0}+nh \\ {y}_{n}={y}_{n-1}+hf({x}_{n-1},{y}_{n-1}),\text{where}\ h\ \text{is the step size}\end{array}\)

Direction Fields and Numerical Methods

For the following problems, use the direction field below from the differential equation \(y'=-2y.\) Sketch the graph of the solution for the given initial conditions.

For the following problems, use the direction field below from the differential equation \(y'={y}^{2}-2y.\) Sketch the graph of the solution for the given initial conditions.

Draw the direction field for the following differential equations, then solve the differential equation.

Draw the directional field for the following differential equations. What can you say about the behavior of the solution? Are there equilibria? What stability do these equilibria have?

Match the direction field with the given differential equations. Explain your selections.




Match the direction field with the given differential equations. Explain your selections.




Estimate the following solutions using Euler’s method with \(n=5\) steps over the interval \(t=[0,1].\) If you are able to solve the initial-value problem exactly, compare your solution with the exact solution. If you are unable to solve the initial-value problem, the exact solution will be provided for you to compare with Euler’s method. How accurate is Euler’s method?

\[\begin{array}{l}S'=rI-cSI\ \text{and} \\ I'=cSI-rI.\end{array}\]

Condensed — the full section is in OpenStax Calculus Volume 2.

Practice (40)

Try each one on paper first. Reveal the answer to check; verified ones can be opened in the solver for every step.

  1. Create a direction field for the differential equation \(y'={x}^{2}-{y}^{2}\) and sketch a solution curve passing through the point \((-1,2).\)

    ਜਵਾਬ ਦਿਓ


  2. Create a direction field for the differential equation \(y'={(y-3)}^{2}({y}^{2}+y-2)\) and identify any equilibrium solutions. Classify each of the equilibrium solutions as stable, unstable, or semi-stable.

    ਜਵਾਬ ਦਿਓ

    The direction field is shown in .

    The equilibrium solutions are \(y=-2,y=1,\) and \(y=3.\) To classify each of the solutions, look at an arrow directly above or below each of these values. For example, at \(y=-2\) the arrows directly below this solution point up, and the arrows directly above the solution point down. Therefore all initial conditions close to \(y=-2\) approach \(y=-2,\) and the solution is stable. For the solution \(y=1,\) all initial conditions above and below \(y=1\) are repelled (pushed away) from \(y=1,\) so this solution is unstable. The solution \(y=3\) is semi-stable, because for initial conditions slightly greater than \(3,\) the solution approaches infinity, and for initial conditions slightly less than \(3,\) the solution approaches \(y=3.\)

  3. Create a direction field for the differential equation \(y'=(x+5)(y+2)({y}^{2}-4y+4)\) and identify any equilibrium solutions. Classify each of the equilibrium solutions as stable, unstable, or semi-stable.

    ਜਵਾਬ ਦਿਓ



    The equilibrium solutions are \(y=-2\) and \(y=2.\) For this equation, \(y=-2\) is an unstable equilibrium solution, and \(y=2\) is a semi-stable equilibrium solution.

  4. Consider the initial-value problem

    \[{y}^{'}=3{x}^{2}-{y}^{2}+1,\ y(0)=2.\]

    Use Euler’s method with a step size of \(0.1\) to generate a table of values for the solution for values of \(x\) between \(0\) and \(1.\)

    ਜਵਾਬ ਦਿਓ

    We are given \(h=0.1\) and \(f(x,y)=3{x}^{2}-{y}^{2}+1.\) Furthermore, the initial condition \(y(0)=2\) gives \({x}_{0}=0\) and \({y}_{0}=2.\) Using with \(n=0,\) we can generate .

    \(n\)\({x}_{n}\)\({y}_{n}={y}_{n-1}+hf({x}_{n-1},{y}_{n-1})\)
    \(0\)\(0\)\(2\)
    \(1\)\(0.1\)\({y}_{1}={y}_{0}+hf({x}_{0},{y}_{0})=1.7\)
    \(2\)\(0.2\)\({y}_{2}={y}_{1}+hf({x}_{1},{y}_{1})=1.514\)
    \(3\)\(0.3\)\({y}_{3}={y}_{2}+hf({x}_{2},{y}_{2})=1.3968\)
    \(4\)\(0.4\)\({y}_{4}={y}_{3}+hf({x}_{3},{y}_{3})=1.3287\)
    \(5\)\(0.5\)\({y}_{5}={y}_{4}+hf({x}_{4},{y}_{4})=1.3001\)
    \(6\)\(0.6\)\({y}_{6}={y}_{5}+hf({x}_{5},{y}_{5})=1.3061\)
    \(7\)\(0.7\)\({y}_{7}={y}_{6}+hf({x}_{6},{y}_{6})=1.3435\)
    \(8\)\(0.8\)\({y}_{8}={y}_{7}+hf({x}_{7},{y}_{7})=1.4100\)
    \(9\)\(0.9\)\({y}_{9}={y}_{8}+hf({x}_{8},{y}_{8})=1.5032\)
    \(10\)\(1.0\)\({y}_{10}={y}_{9}+hf({x}_{9},{y}_{9})=1.6202\)

    With ten calculations, we are able to approximate the values of the solution to the initial-value problem for values of \(x\) between \(0\) and \(1.\)

  5. Consider the initial-value problem

    \[{y}^{'}={x}^{3}+{y}^{2},\ y(1)=-2.\]

    Using a step size of \(0.1,\) generate a table with approximate values for the solution to the initial-value problem for values of \(x\) between \(1\) and \(2.\)

    ਜਵਾਬ ਦਿਓ
    \(n\)\({x}_{n}\)\({y}_{n}={y}_{n-1}+hf({x}_{n-1},{y}_{n-1})\)
    \(0\)\(1\)\(-2\)
    \(1\)\(1.1\)\({y}_{1}={y}_{0}+hf({x}_{0},{y}_{0})=-1.5\)
    \(2\)\(1.2\)\({y}_{2}={y}_{1}+hf({x}_{1},{y}_{1})=-1.1419\)
    \(3\)\(1.3\)\({y}_{3}={y}_{2}+hf({x}_{2},{y}_{2})=-0.8387\)
    \(4\)\(1.4\)\({y}_{4}={y}_{3}+hf({x}_{3},{y}_{3})=-0.5487\)
    \(5\)\(1.5\)\({y}_{5}={y}_{4}+hf({x}_{4},{y}_{4})=-0.2442\)
    \(6\)\(1.6\)\({y}_{6}={y}_{5}+hf({x}_{5},{y}_{5})=0.0993\)
    \(7\)\(1.7\)\({y}_{7}={y}_{6}+hf({x}_{6},{y}_{6})=0.5099\)
    \(8\)\(1.8\)\({y}_{8}={y}_{7}+hf({x}_{7},{y}_{7})=1.0272\)
    \(9\)\(1.9\)\({y}_{9}={y}_{8}+hf({x}_{8},{y}_{8})=1.7159\)
    \(10\)\(2\)\({y}_{10}={y}_{9}+hf({x}_{9},{y}_{9})=2.6962\)
  6. Are there any equilibria? What are their stabilities?

    ਜਵਾਬ ਦਿਓ

    \(y=0\) is a stable equilibrium

  7. Are there any equilibria? What are their stabilities?

    ਜਵਾਬ ਦਿਓ

    \(y=0\) is a stable equilibrium and \(y=2\) is unstable

  8. \(y'={t}^{3}\)

  9. \(y'={e}^{t}\)

    ਜਵਾਬ ਦਿਓ

    General solution is \(y={e}^{t}+C\).

  10. \(\frac{dy}{dx}={x}^{2}\text{cos}\ x\)

  11. \(\frac{dy}{dt}=t{e}^{t}\)

    ਜਵਾਬ ਦਿਓ

    General solution is \(y={e}^{t}(t-1)+C\).

  12. \(\frac{dx}{dt}=\text{cosh}(t)\)

  13. \(y'={y}^{2}-1\)

    ਜਵਾਬ ਦਿਓ


  14. \(y'=1-{y}^{2}-{x}^{2}\)

    ਜਵਾਬ ਦਿਓ


  15. \(y'={t}^{2}\text{sin}\ y\)

  16. \(y'=3y+xy\)

    ਜਵਾਬ ਦਿਓ


  17. \(y'={e}^{t}\)

  18. \(y'=\frac{1}{2}y+t\)

    ਜਵਾਬ ਦਿਓ

    A

  19. \(y'=\text{-}ty\)

  20. \(y'=t\ \text{sin}\ y\)

    ਜਵਾਬ ਦਿਓ

    B

  21. \(y'=\text{-}t\ \text{cos}\ y\)

  22. \(y'=t\ \text{tan}\ y\)

    ਜਵਾਬ ਦਿਓ

    A

  23. \(y'={\text{sin}}^{2}y\)

  24. \(y'={y}^{2}{t}^{3}\)

    ਜਵਾਬ ਦਿਓ

    C

  25. \(y'=-3y,\ y(0)=1\)

  26. \(y'={t}^{2},y(0)=2\)

    ਜਵਾਬ ਦਿਓ

    \(2.24,\) exact: \(2\)

  27. \({y}^{'}=3t-y,y(0)=1.\) Exact solution is \(y=3t+4{e}^{\text{-}t}-3\)

  28. \({y}^{'}=y+{t}^{2},y(0)=3.\) Exact solution is \(y=5{e}^{t}-2-{t}^{2}-2t\)

    ਜਵਾਬ ਦਿਓ

    \(7.739264,\) exact: \(5(e-1)\)

  29. \({y}^{'}=2t,y(0)=0\)

  30. [T] \(y'={e}^{(x+y)},y(0)=-1.\) Exact solution is \(y=\text{-}\text{ln}(e+1-{e}^{x})\)

    ਜਵਾਬ ਦਿਓ

    \(-0.2535\) exact: \(0\)

  31. \({y}^{'}={y}^{2}\text{ln}(x+1),y(0)=1.\) Exact solution is \(y=-\frac{1}{(x+1)(\text{ln}(x+1)-1)}\)

  32. \({y}^{'}={2}^{x},y(0)=0,\) Exact solution is \(y=\frac{{2}^{x}-1}{\text{ln}(2)}\)

    ਜਵਾਬ ਦਿਓ

    \(1.345,\) exact: \(\frac{1}{\text{ln}(2)}\)

  33. \({y}^{'}=y,y(0)=-1.\) Exact solution is \(y=\text{-}{e}^{x}.\)

  34. \({y}^{'}=-5t,y(0)=-2.\) Exact solution is \(y=-\frac{5}{2}{t}^{2}-2\)

    ਜਵਾਬ ਦਿਓ

    \(-4,\) exact: \(\text{-}1\text{/}2\)

  35. Show that, by our assumption that the total population size is constant \((S+I=N),\) you can reduce the system to a single differential equation in \(I\text{:}\ I'=c(N-I)I-rI.\)

  36. Assuming the parameters are \(c=0.5,N=5,\) and \(r=0.5,\) draw the resulting directional field.

    ਜਵਾਬ ਦਿਓ


  37. [T] Use computational software or a calculator to compute an approximate solution to the initial-value problem \(y'=ty,\ y(0)=2\) using Euler's Method with a given step size \(h.\) Find the solution at \(t=1\) in terms of \(h.\) Hint: Here is "pseudo-code" for how to write a computer program to perform Euler's Method for \(y'=f(t,y),y(0)={y}_{0}\text{:}\)

    • Create function \(f(t,y).\)

    • Define parameters \(y(0)={y}_{0},\ t(0)=0,\) step size \(h,\) and total number of steps, \(N\)

    • Write a for loop:

      for \(\text{k}=0\ \text{to}\ N\)

      \(\ \text{fn}=\text{f}(\text{t}(\text{k}),\text{y}(\text{k}))\)

      \(\ \text{y}(\text{k+1})=\text{y}(\text{k})+\text{h*fn}\)

      \(\ \text{t}(\text{k+1})=\text{t}(\text{k})+\text{h}\)

  38. Solve the initial-value problem for the exact solution.

    ਜਵਾਬ ਦਿਓ

    \(y'=2{e}^{{t}^{2}\text{/}2}\)

  39. Draw the directional field

  40. Compute using \(h=1\)

    ਜਵਾਬ ਦਿਓ

    \(2\)

Symbols used here

f'(x),\ \frac{dy}{dx}
derivative
Instantaneous rate of change; slope of the graph.
y',\ y''
first and second derivative of y
Prime notation for derivatives with respect to x (or t).
^\circ
degrees
1/360 of a full turn. 180° = π radians.
\pi
pi
Ratio of a circle's circumference to its diameter, 3.14159…
e
Euler's number
2.71828…, the base whose exponential is its own derivative.
\infty
infinity
Not a number: "grows without bound" in limits and intervals.
\sin,\ \cos,\ \tan
sine, cosine, tangent
Ratios of sides in a right triangle; coordinates on the unit circle.
\log_b x,\ \ln x
logarithm, natural log
The exponent b must be raised to for x; ln uses base e.
\sum_{k=1}^{n} a_k
summation
Add a_k for k = 1 up to n.
\lim_{x \to a} f(x)
limit
The value f(x) approaches as x approaches a.
\int f(x)\,dx,\ \int_a^b
integral
Antiderivative (indefinite) or signed area from a to b (definite).
C,\ C_1,\ C_2
arbitrary constants
Constants of integration fixed by initial conditions.

How to: Direction Fields and Numerical Methods

  1. Draw the direction field for a given first-order differential equation.
  2. Use a direction field to draw a solution curve of a first-order differential equation.
  3. Use Euler’s Method to approximate the solution to a first-order differential equation.
  4. A direction field is a mathematical object used to graphically represent solutions to a first-order differential equation.
  5. Euler’s Method is a numerical technique that can be used to approximate solutions to a differential equation.

Questions people ask

What is a derivative in one sentence?

The slope of the graph at a point — the rate at which the output is changing there. Speed is the derivative of position.

What is an integral in one sentence?

The accumulated total of a rate — the area under the curve. Distance travelled is the integral of speed.

Why are derivatives and integrals opposites?

That is the fundamental theorem of calculus: accumulating a rate and then measuring how fast the accumulation grows gets you back the rate. Integration undoes differentiation up to a constant.

When do I use substitution and when integration by parts?

Substitution when part of the integrand is the derivative of another part (u and du both present). Parts when the integrand is a product of two unrelated kinds of function — a polynomial times an exponential, log or trig function.

ਆਪਣਾ ਹੀ ਕੋਸ਼ਿਸ਼ ਕਰੋ

Parts of this page are adapted from OpenStax Calculus Volume 2 (CC BY-NC-SA 4.0). Condensed and re-explained here; errors are ours.

ਹੋਰ ਵਿੱਚ Calculus