Skip to main content
Mathematics LibreTexts

1.1 Modeling and Direction Fields

  • Page ID
    155931
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\dsum}{\displaystyle\sum\limits} \)

    \( \newcommand{\dint}{\displaystyle\int\limits} \)

    \( \newcommand{\dlim}{\displaystyle\lim\limits} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \(\newcommand{\longvect}{\overrightarrow}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)
    Definition \(\PageIndex{1}\): Differential Equation

    differential equation is an equation that relates a function to one or more of its derivatives.

    Examples

    1) \(\sum F = m\frac{dv}{dt}\) - Newton's 2nd Law (assuming constant mass) relates the net force \(\sum F\) acting on a mass \(m\) to the rate of change of its velocity \(v(t)\).
    2) \(\frac{dT}{dt} = -k(T-T_{\text{env}})\) - Newton's Law of Cooling models how an object's temperature \(T(t)\) changes over time as it exchanges heat with an environment held at temperature \(T_{\text{env}}\) with cooling rate \(k\).
    3) \(m\frac{d^2x}{dt^2} + kx = 0\) - Mass-Spring System relates the acceleration \(m\frac{d^2x}{dt^2}\) of a mass \(m\) attached to a spring with stiffness \(k\), where \(x(t)\) represents the displacement from its equilibrium length.

    In this text we will typically try to model a physical or mathematical situation with a differential equation, and attempt to determine all of its solutions.

    Solutions of differential equations are functions.

    Example \(\PageIndex{2}\)

    Consider an object in free fall with mass \(m\). Since the object is falling, let's consider the downward direction as positive. From Newton's 2nd Law above, we see that

    \[ \notag
    \sum F = m\frac{dv}{dt}.1.1 - Free-body Diagram.png
    \]

    For simplicity, we can suppose there are two forces \(F_1\) and \(F_2\) acting on it:

    • \(F_1 = mg\); the force due to gravity. It is positive since the object is falling downward due to gravity. On Earth, we have \(g \approx 9.8 \,\, \frac{\text{m}}{\text{s}^2}.
    • \(F_2 = -\gamma v\); the force due to air resistance. It is negative since the air exerts an upward force to resist the falling object. For simplicity, assume the drag coefficient \(\gamma\) is constant.

    Rewriting our equation, we now have

    \[ \notag
    m\frac{dv}{dt} = \sum F = mg - \gamma v \quad \Longleftrightarrow \quad \frac{dv}{dt} = g - \frac{\gamma}{m} v.
    \]

    A solution to this equation is a velocity function \(v(t)\) for the object. We will learn how to solve for an expression for \(v(t)\) in the next section. Despite this, we can still learn information about it. To make this more concrete, let's upgrade our example by assuming

    \[ \notag
    g = 9.8 \,\, \frac{\text{m}}{\text{s}^2}, \quad m = 10 \,\, \text{kg}, \quad \gamma = 2 \,\, \frac{\text{kg}}{\text{s}},
    \]

    so that our equation becomes

    \[ \notag
    10\frac{dv}{dt} = 10(9.8)-2v \quad \Longleftrightarrow \quad \frac{dv}{dt} = 9.8 - \frac{v}{5}.
    \]

    In the plot below, we have placed short arrows with slope \(\left.\frac{dv}{dt}\right|_{(t,v)} = 9.8 - \frac{v}{5}\) at multiple locations \((t,v)\) in the plane. For example,

    • if \(v=40\) then \(\frac{dv}{dt} = 9.8 - \frac{40}{5} = 1.8\) (Recall that the downward direction is positive),
    • if \(v=50\) then \(\frac{dv}{dt} = 9.8 - \frac{40}{5} = -0.2\),
    • if \(v=60\) then \(\frac{dv}{dt} = 9.8 - \frac{40}{5} = -2.2\),
    • Observe that \(\frac{dv}{dt} = 0\) when \(v = 5(9.8) = 49\).
    import matplotlib.pyplot as plt
    import numpy as np
    from sympy import var, plot_implicit
    
    #Seting up the grid for us to put the arrows on
    nx, ny = 1, 1
    x = np.arange(0, 20, nx)
    y = np.arange(40, 60, ny)
    X, Y = np.meshgrid(x, y)
    
    #this is the original equation
    dy = 49 - Y
    dx = np.ones(dy.shape)
    
    #normalized rates of change
    dyn = dy/np.sqrt(dy**2 +dx**2)
    dxn = dx/np.sqrt(dy**2 +dx**2)
    
    
    
    plt.rcParams['figure.figsize'] = [10, 10]
    plot1 = plt.plot()
    plt.quiver(X, Y, dxn, dyn, 
               color='Blue', 
               headlength=5) #this is the direction field with normalized arrow size
    plt.show()

    The object must have some initial velocity \(v(0) = v_0\) corresponding to a point \((0, v_0)\) in the plot. The arrows then tell us where this point would travel next, and the path that this point traces is the graph of the solution \(v(t)\) with initial condition (\v(0) = v_0\). We can see this in the manimation below:
    (insert 1.1-Freefall.mp4)

     

    The usefulness of the plot in the previous example motivates the following definition.

    Definition \(\PageIndex{3}\): Direction Field

    Consider the differential equation \(\frac{dy}{dt} = f(t,y)\), for some function \(f\). A solution to this equation is a function \(y(t)\), and evaluating \(f\) at \((t, y)\) gives the slope of the tangent line to \(y\) at \((t,y)\):

    \[ \notag
    \left. \frac{dy}{dt} \right|_{(t,y)} = f(t,y).
    \]

    direction field (for this differential equation) is a collection of short arrows with slope \(f(t,y)\) at locations \((t,y)\).

    2.) Mouse population increases at a rate proportional to the current population:

    More general model : \(\frac{d p}{d t}=r p-k\) where \(p(t)=\) mouse population at time \(t\), \(r=\) growth rate or rate constant, \(k=\) predation rate \(=\) number of mice killed per unit time. Thus for \(r>0\) the solutions diverge from the equilibrium solutions. 

    import matplotlib.pyplot as plt
    import numpy as np
    from sympy import var, plot_implicit
    
    #Seting up the grid for us to put the arrows on
    nx, ny = 1, 1
    x = np.arange(-10, 10, nx)
    y = np.arange(40, 60, ny)
    X, Y = np.meshgrid(x, y)
    
    #this is the original equation
    dy = Y-50
    dx = np.ones(dy.shape)
    
    #normalized rates of change
    dyn = dy/np.sqrt(dy**2 +dx**2)
    dxn = dx/np.sqrt(dy**2 +dx**2)
    
    
    
    plt.rcParams['figure.figsize'] = [10, 10]
    plot1 = plt.plot()
    plt.quiver(X, Y, dxn, dyn, 
               color='Blue', 
               headlength=5) #this is the direction field with normalized arrow size
    plt.show()

    3.) Continuous compounding \(\frac{d S}{d t}=r S+k\) where \(S(t)=\) amount of money at time \(t\), \(r=\) interest rate,
    \(k=\) constant deposit rate.

    Interactive Direction field

    You code below looks at the differential equation \(dy = k\cdot Y -50\), the slider allows us to manipulate different values of \(k\) to see how the direction field changes. It should be noted that the arrows are normalized and thus all have a length of 1.

    import ipywidgets as widgets
    import matplotlib.pyplot as plt
    import numpy as np
    from sympy import var, plot_implicit
    
    
    #Seting up the grid for us to put the arrows on
    nx, ny = 2, 2
    x = np.arange(-10, 10, nx)
    y = np.arange(20, 60, ny)
    X, Y = np.meshgrid(x, y)
    d_y = Y-50
    d_x = np.ones(d_y.shape)
    
    
    def dy(k):
        return (k*Y-50) #this is just a function for the rate of change of y to be manipulated with the slider.
    
    @widgets.interact(k=(0, 2, 0.01)) #creating the slider and the direction field to be changed as the slider moves
    def update(k = 1):
      plt.rcParams['figure.figsize'] = [10, 10]
      plt.clf()
      plt.ylim(20, 60)
      plt.quiver(X, Y, 2*d_x/np.sqrt((dy(k))**2 +d_x**2), 2*dy(k)/np.sqrt((dy(k))**2 +d_x**2), 
               color='Blue', 
               headlength=5)
     
    1.00

    direction field \(=\) slope field \(=\) graph of \(\frac{d y}{d t}\) in \(t, y\) plane.

    import matplotlib.pyplot as plt
    import numpy as np
    from sympy import var, plot_implicit
    
    #Seting up the grid for us to put the arrows on
    nx, ny = .3, .3
    x = np.arange(-4, 4, nx)
    y = np.arange(-4, 4, ny)
    X, Y = np.meshgrid(x, y)
    
    #this is the original equation
    dy = (X+1)
    dx = np.ones(dy.shape)
    
    #normalized rates of change
    dyn = dy/np.sqrt(dy**2 +dx**2)
    dxn = dx/np.sqrt(dy**2 +dx**2)
    
    var('x y')
    eq = y-(x**2)/2-x #this is the solution to the system without the C
    s=plot_implicit(eq,(x,-4,4),(y,-4,4), line_color='Red',show=False) #this is the implicit graph of the solution with c=0.
    C = [-2,-1,1,2] #these are all the values of C that will be added to eq and graphed.
    
    for c in C: #makes all of the implicit solutions on the same plot.
    	s.append(plot_implicit(y-(x**2)/2-x + c,(x,-4,4),(y,-4,4), line_color='Red',show=False)[0])
        
    backend = s.backend(s)
    backend.process_series() #Allows us to combine the implicit solutions and plt.quiver
    
    plt.rcParams['figure.figsize'] = [10, 10]
    plot1 = plt.plot()
    plt.quiver(X, Y, dxn, dyn, 
               color='Blue', 
               headlength=5) #this is the direction field with normalized arrow size
    plt.show()

     

    import ipywidgets as widgets
    import matplotlib.pyplot as plt
    import numpy as np
    from sympy import var, plot_implicit
    
    #Seting up the grid for us to put the arrows on
    nx, ny = .3, .3
    x = np.arange(-4, 4, nx)
    y = np.arange(-4, 4, ny)
    X, Y = np.meshgrid(x, y)
    X, Y = np.meshgrid(x, y)
    d_y = X+1
    d_x = np.ones(d_y.shape)
    
    
    def dy(k):
        return (k*X+1) #this is just a function for the rate of change of y to be manipulated with the slider.
    
    @widgets.interact(k=(0, 2, 0.01)) #creating the slider and the direction field to be changed as the slider moves
    def update(k = 1):
      plt.rcParams['figure.figsize'] = [10, 10]
      var('x y')
      eq = y-(k*x**2)/2-x #this is the solution to the system without the C
      s=plot_implicit(eq,(x,-4,4),(y,-4,4), line_color='Red',show=False) #this is the implicit graph of the solution with c=0.
      C = [-2,-1,1,2] #these are all the values of C that will be added to eq and graphed.
      for c in C: #makes all of the implicit solutions on the same plot.
       s.append(plot_implicit(y-(k*x**2)/2-x + c,(x,-4,4),(y,-4,4), line_color='Red',show=False)[0])
      backend = s.backend(s)
      backend.process_series() #Allows us to combine the implicit solutions and plt.quiver
      plt.quiver(X, Y, d_x/np.sqrt((dy(k))**2 +d_x**2), dy(k)/np.sqrt((dy(k))**2 +d_x**2), 
               color='Blue', 
               headlength=5)
     
    1.00
    Note

    Direction fields can use slope field to determine behavior of \(y\) increasing as \(t \rightarrow \pm \infty\).

    Note

    Equilibrium Solution \(=\) constant solution


    Most differential equations do not have an equilibrium solution. 

    Definition \(\PageIndex{4}\): Initial value

    A chosen point \(\left(t_0, y_0\right)\) through which a solution must pass. I.e., \(\left(t_0, y_0\right)\) lies on the graph of the solution that satisfies this initial value.

    An initial value problem can have \(0\), \(1\), or multiple equilibrium solutions. 

    Example \(\PageIndex{5}\)

    Solve \(\frac{d v}{d t}=9.8-\frac{v}{5}\)

    Solution

    \(\begin{array}{l}5 d t \frac{d v}{d t}=\left(9.8-\frac{v}{5}\right) 5 d t \Rightarrow 5 d v=(49-v) d t \\ \frac{5 d v}{49-v}=d t \\ \int \frac{5 d v}{49-v}=\int d t \Rightarrow-5 \ln |49-v|=t+C \\ \ln |49-v|=\frac{-t}{5}+C \Rightarrow e^{\ln |49-v|}=e^{\frac{-t}{5}+C}=e^{\frac{-t}{5}} e^C\end{array}\)

    \(\begin{array}{l}|49-v|=C e^{\frac{-t}{5}} \\ 49-v= \pm C e^{\frac{-t}{5}} \\ -v=C e^{\frac{-t}{5}}-49 \\ v=C e^{\frac{-t}{5}}+49\end{array}\)

     

    Example \(\PageIndex{6}\)

    Initial Value Problem (IVP):
    Solve \(\frac{d v}{d t}=9.8-\frac{v}{5}, \quad v(0)=0\)

    Applicaton: Find the velocity at time \(t\) if a ball with mass \(10 \mathrm{~kg}\) is dropped from a building. Assume air resistence is proportial to velocity with proportionality constant \(2 \mathrm{~kg} / \mathrm{sec}\).

    Solution

    To solve IVP,

    1. Solve DE: \(\frac{d v}{d t}=9.8-\frac{v}{5} \Rightarrow v=C e^{\frac{-t}{5}}+49\)
    2. Plug in initial value, \(v(0)=0\), to determine \(C\) : 

    \[ \notag
    v=C e^{\frac{-t}{5}}+49 \implies 0=C e^{\frac{0}{5}}+49 \implies 0 = C +49 \implies C=-49
    \]

    Thus we have the solution to the IVP is: \( v=-49 e^{\frac{-t}{5}}+49 .\)

    We can see that this is correct by using the slider on the script below to change the values of c in the expression \( v=-49 e^{\frac{-t}{5}}+49 .\) Note that the arrows in the direction field are not changing as all of these are solutions to the differential equation.

     

    import ipywidgets as widgets
    import matplotlib.pyplot as plt
    import numpy as np
    from sympy import var, plot_implicit, exp
    
    #Seting up the grid for us to put the arrows on
    nx, ny = .3, .3
    x = np.arange(-2, 2, nx)
    y = np.arange(-2, 2, ny)
    X, Y = np.meshgrid(x, y)
    X, Y = np.meshgrid(x, y)
    d_y = 9.8 - Y/5
    d_x = np.ones(d_y.shape)
    
    
    @widgets.interact(c=(-60, -35, 0.5)) #creating the slider and the direction field to be changed as the slider moves
    def update(c = -35):
      plt.rcParams['figure.figsize'] = [10, 10]
      var('x y')
      eq = -y+c*(exp(-x/5))+49 #this is the solution to the system without the C
      s=plot_implicit(eq,(x,-2,2),(y,-2,2), line_color='Red',show=False) #this is the implicit graph of the solution with c=0.
      backend = s.backend(s)
      backend.process_series() #Allows us to combine the implicit solutions and plt.quiver
      plt.quiver(X, Y, d_x/np.sqrt((d_y)**2 +d_x**2), d_y/np.sqrt((d_y)**2 +d_x**2), 
               color='Blue', 
               headlength=5)
     
    -49.00

     


    This page titled 1.1 Modeling and Direction Fields is shared under a not declared license and was authored, remixed, and/or curated by Isabel K. Darcy.

    • Was this article helpful?