Skip to main content
Mathematics LibreTexts

31.3: Ordinary Differential Equations

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

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

    \( \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{\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}\)

    Ordinary Differential Equations (ODEs) are yet another for of linear dynamical systems and are a scientific model used in a wide range of problems of the basic form:

    \[\dot{x} = Ax \nonumber \]

    These are equations such that the is the instantaneous rate of change in \(x\) (i.e. \(\dot{x}\) is the derivative of \(x\)) is dependent on \(x\). Many systems can be modeled with these types of equations.

    Here is a quick video that introduces the concepts of Differential Equations. The following is a good review of general ODEs.

    from IPython.display import YouTubeVideo
    YouTubeVideo("8QeCQn7uxnE",width=640,height=360, cc_load_policy=True)

    Now consider an ODE as a system of linear equations:

    \[\dot{x_t} = A x_t \nonumber \]

    Based on the current \(x\) vector at time \(t\) and the matrix \(A\), we can calculate the derivative at \(\dot{x}\) at time \(t\). Once we know the derivative, we can increment the time to by some small amount \(dt\) and calculate a new value of \(x\) as follows:

    \[x_{t+1} = x_t + \dot{x_t}dt \nonumber \]

    Then we can do the exact sequence of calculations again for \(t+2\). The following function has the transition matrix (\(A\)), the starting state vector (\(x_0\)) and a number of time steps (\(N\)) and uses the above equations to calculate each state and return all of the \(x\) statues:

    The following code generates a trajectory of points starting from x_0, applying the matrix \(A\) to get \(x_1\) and then applying \(A\) again to see how the system progresses from the start state.

    %matplotlib inline
    import matplotlib.pylab as plt
    import numpy as np
    import sympy as sym
    sym.init_printing()
    def traj(A, x, n):
        dt = 0.01
        x_all = np.matrix(np.zeros((len(x),n)))   # Store all points on the trajectory
        for i in range(n):  
            x_dot = A*x         # First we transform x into the derrivative
            x = x + x_dot*dt    # Then we estimate x based on the previous value and a small increment of time.
            x_all[:,i] = x[:,0] 
        return x_all

    For example the following code uses the matrix \(A= \begin{bmatrix}1 & 1 \\ 1 & -2\end{bmatrix}\) and the starting point (0,0) over 50 timesteps to get a graph:

    A = np.matrix([[1,1],[1,-2]])
    x0 = np.matrix([[1],[1]])
    
    x_all = traj(A, x0, 50)
    plt.scatter(np.asarray(x_all[0,:]),np.asarray(x_all[1,:]))
    
    plt.scatter(list(x0[0,:]),list(x0[1,:])) #Plot the start point as a refernce
    Do This

    Let \(A= \begin{bmatrix}2 & 3 \\ 4 & -2\end{bmatrix}\)

    Write a loop over the points \((−1.5,−1), (−1,2)(−1,2)\) and plot the results of the traj function:

    A = np.matrix([[2,3],[4,-2]])
    x0 = np.matrix([[1.5, -1.5, -1, 1, 2],[1, -1, 2, -2, -2]])
    # Put your code here
    Do This

    Let \(A= \begin{bmatrix}6 & -1 \\ 1 & 4\end{bmatrix}\)

    Write a loop over the points \((−1.5,−1), (−1,2)(−1,2)\) and plot the results of the traj function:

    # Put your code here
    Do This

    Let \(A= \begin{bmatrix}5 & 2 \\ -4 & 1\end{bmatrix}\)

    Write a loop over the points \((−1.5,−1), (−1,2)(−1,2)\) and plot the results of the traj function:

    # Put your code here

    This page titled 31.3: Ordinary Differential Equations is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Dirk Colbry via source content that was edited to the style and standards of the LibreTexts platform.

    • Was this article helpful?