11.8. JNB Lab: Differential Equations#

11.8.1. Chapter Review#

Note

This first section of practice problems can serve as a review of the topics covered in the Differential Equations chapter organized by section; most of these questions can (and should) be completed by hand. It is followed by a series of problems drawing from the material of the chapter overall, which should be completed using code.

Section 2 Questions#

  1. List the type, order, and parameters of each of the following differential equations. For each ordinary differential equation, determine if it is linear or nonlinear.

    • \(\dfrac{dy}{dx} +3x^2 = sin(x) + 3\)

    • \((\dfrac{dy}{dx})^2 +3x^2 = sin(x) + 3\)

    • \(\dfrac{dy}{dx}k +3x^2 k = y\,sin(x) + 3\)

    • \(\dfrac{d^2y}{dx^2} +3x^2 = sin(x) + 3\)

\( \)

  1. List the type, order, and parameters of each of the following differential equations. For each ordinary differential equation, determine if it is linear or nonlinear.

    • \(\frac{\partial w}{\partial u} + \frac{\partial^2 w}{\partial v^2} = u\)

    • \(\frac{\partial w}{\partial u} + \frac{\partial w}{\partial v} = u^2\)

    • \(\dfrac{dt}{dv}t = tan(t) +9\)

    • \(\dfrac{dt}{dv}v = tan(t) +9\)

\( \)

  1. Show that \(y = e^{2t}\) is a solution for all \(t\) to \(y''+y = 5y\).

  2. Show that \(y = te^{5t}\) is a solution for all \(t\) to \(y''-10y'=-25y\).

  3. Show that \(y = sin(3t)+cos(3t) + t^3 -6\) is a solution for all \(t\) to \(y'''+9y' = 27t^2+6\).

  4. Show that \(y = 12t^2+t^4\) is a solution for all \(t\) to \((y'+y'')-(y'''+y^{(4)}) = y-t^4+4t^3\).

Section 3 Questions#

  1. Solve the separable equations:

    • \( \dfrac{dx}{dt} = \dfrac{1}{t}e^{-2x} \)

    • \( \dfrac{dx}{dt} = \dfrac{-1}{x^2t^2} \)

    • \( \dfrac{dy}{dx} = cos^2(y)e^{x^2}2x \)

    • \( \dfrac{1}{x}-\dfrac{dx}{dt}=x^{-1}\dfrac{1}{sec(t)} \)

  2. Solve the linear equations using the method of integrating factors (\(\mu(t) = e^{P(t)}\)):

    • \( t\dfrac{dx}{dt} = sin(t) -x \)

    • \( \dfrac{dx}{dt} + x 4t^3 = \dfrac{1}{t e^{t^4}} \)

    • \( \dfrac{dy}{dx} + \dfrac{y}{x} = \dfrac{1}{x+x^3} \)

    • \( \dfrac{dy}{dx}x + \dfrac{-2y}{x^2} = xe^{-x^{-2}}sec(x)tan(x) \)

  3. Find the equilibrium solutions and draw the phase lines for the following functions. Classify each equilibrium solution.

    • \( y'=(y-6)(y+7) \)

    • \( y'= y^3-8y^2+12y \)

    • \( y'= y(y^2-1) \)

    • \( y'= y^2(y^2-1) \)

Section 4 Questions#

  1. Solve the initial value problem:

    • \( x'' - x' -42x = 0 \); \( x'(0) = 0\), \( x''(0) = 1\)

    • \( x''-14x'+48x=0 \); \(x'(0)=0\), \(x''(0)=5\)

    • \( x''+6x'+9x=0, x'(0)=0, x''(0)=9 \)

    • \( x''+16x'+64x=0, x'(0)=0, x''(0)=8 \)

    • \( x''+4x'+8x=0, x'(0)=0, x''(0)=4 \)

    • \( x''+10x'+30x=0, x'(0)= 0, x''(0)= 30 \)

  2. Solve the non-homogeneous equations:

    • \( x''-9x'+20x=-10 \)

    • \( x''-9x'+20x=20t^2 \)

    • \( x''-9x'+20x=e^{3t} \)

    • \( x''-9x'+20x=e^{5t} \)

  3. Solve the non-homogeneous equations:

    • \( x''+4x'+4x =sin(t)\)

    • \( x''+4x'+4x =8t^2 \)

Section 5 Questions#

  1. Rewrite as a system of first order equations:

    • \( x'''+3x''+12x'+x=sin(t)+e^{3t} \)

  2. Test the following sets of vectors for linear independence:

    • \(\biggl\{\begin{bmatrix} 2e^{t} \\ e^{12t} \end{bmatrix}, \begin{bmatrix} 12e^{2t} \\ 6e^{12t} \end{bmatrix}\biggr\}\)

    • \(\biggl\{\begin{bmatrix} 5e^{3t} \\ 6e^{6t} \end{bmatrix}, \begin{bmatrix} 10e^{3t} \\ 12e^{6t} \end{bmatrix}\biggr\}\)

    • \(\biggl\{\begin{bmatrix} 3t \\ 1 \end{bmatrix}, \begin{bmatrix} 3t \\ tan^2(t) \end{bmatrix}, \begin{bmatrix} 6t \\ sec^2(t) \end{bmatrix} \biggr\}\)

  3. Find the eigenvalues and eigenvectors:

    • \(\begin{bmatrix} 3&0 \\ 0&4 \end{bmatrix}\)

    • \(\begin{bmatrix} 6&2 \\ -2&2 \end{bmatrix}\)

    • \(\begin{bmatrix} 3&2 \\ -9&-3 \end{bmatrix}\)

  4. Solve the linear systems where \( x'=Ax \) of differential equations, for each choice of A:

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

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

    • \(A=\begin{bmatrix} 6&13 \\ -4&-6 \end{bmatrix}\)

  5. Find the nullclines, equilibrium solutions, and linearization of the system:

    • \( x'=x(1-x)-4xy \); \( y'=y(2-y)-3xy \)

Section 6 Questions#

  1. Solve the following Laplace Transforms by hand, using the formula \(\mathcal{L}(f(t)) = \int_{0}^{\infty} e^{-st}f(t) \mathrm{d}t \equiv F(s).\)

    • \( f(t)= sin(t)\)

    • \( f(t)= cos(t)\)

    • \( f(t)=8t+e^{3t}+cos(3t) \)

  2. Find the inverse Laplace Transforms of the following functions:

    • \( \mathcal{L}(x)=-\dfrac{14}{s^3}+\dfrac{1}{s^2+49} \)

    • \( \mathcal{L}(x)= \dfrac{s+9}{(s+2)(s+3)}\)

    • \( \mathcal{L}(x)= x''+12x=3, x(0)=x'(0)=0 \)

  3. Express the following functions in terms of the unit step function, then take the Laplace Transform:

    • \( f(t) = \begin{cases} 0 & \text{ if } t < 2 \\ 1 & \text{ if } t>2 \end{cases} \)

    • \( f(t) = \begin{cases} 2 & \text{ if } 0< t < 1 \\ 3 & \text{ if } 1<t<2 \\ 4 & \text{ if } t>2 \end{cases} \)

11.8.2. Python Questions#

import sympy as sp

Note

Now that we have practiced solving differential equations by hand, we review some tools and implement new ones to solve differential equations using Python code.

First and second order equations#

First and second order equations can be solved fairly easily by using Sympy:

Example: Solve \( \dfrac{dy}{dx} =3x^2\,y\)

x = symbols("x") #Independent variable
y = Function("y") #Dependent variable
ex = 3*x**2 *y(x) - y(x).diff(x) #Enter the function
ex
\[\displaystyle 3 x^{2} y{\left(x \right)} - \frac{d}{d x} y{\left(x \right)}\]
dsolve(ex) #Solve the equation
\[\displaystyle y{\left(x \right)} = C_{1} e^{x^{3}}\]
  1. Solve \( \dfrac{dy}{dx}= 3x^2y \) using Sympy code

  2. Solve \(y'' + 3y = 0\)

  3. Solve \( \dfrac{dy}{dx}= cos(x)+3y \)

  4. Solve \( x''+2x'+2x=12 \)

  5. Solve \( \dfrac{dy}{dx} = \dfrac{1}{(1+x^2)}y^2 \)

Direction Fields#

Use Python code to plot the direction fields:

  1. \( \dfrac{dy}{dx}= x^2-y^2-y \)

  2. \( \dfrac{dy}{dx}= x(y-x) \)

  3. \( \dfrac{dy}{dx}= y(x-y) \)

Phase Planes and Phase Portraits#

Edit the code from Section 5.4 to plot the phase planes, then find the equilibrium solutions:

  1. \( \dfrac{dx}{dt}= x (x + 3) - 2xy \), \( \dfrac{dy}{dt} = y (3y - 8) - xy \)

  2. \( \dfrac{dx}{dt} = x (5 - 2x) + xy\), \( \dfrac{dy}{dt} = y (y + 1) + y\)
    Edit the code from Section 5.4 to plot the phase portraits of the same systems

  3. \( \dfrac{dx}{dt}= x (x + 3) - 2xy \), \( \dfrac{dy}{dt} = y (3y - 8) - xy \)

  4. \( \dfrac{dx}{dt} = x (5 - 2x) + xy\), \( \dfrac{dy}{dt} = y (y + 1) + y\)

Nullclines#

Plot the nullclines for the following system:

  • \( x'=x(1-x)-4xy \); \( y'=y(2-y)-3xy \)

Laplace Transforms#

Note

Laplace Transforms can also be solved using code- we will utilize both the Sympy and Numpy libraries

Example: Find the Laplace Transform of \( f(t)= sin(t)\)

import numpy as np
import matplotlib.pyplot as plt
import sympy as sym
from sympy.abc import s,t
f = sym.sin(t)  # define your function with respect to t
F = sym.laplace_transform(f, t, s)  # sym.laplace_transform_(function, func_var, out_var)

print(F)  # returns F(s) and convergence interval
(1/(s**2 + 1), 0, True)

Example: Find the Inverse Laplace Transform of \( f(t) = \dfrac{1}{s^2+1} \)

# Define the inverse Laplace transform function
def invL(F):
    return sym.inverse_laplace_transform(F, s, t)

F= 1/(s**2+1)
print(invL(F))
sin(t)*Heaviside(t)

Note: Heaviside(t) means that \( t \geq 0\)

Example: Solve the initial value problem

\[y'' + 4y'+3y = 10\cos(t), \quad y(0)=2, \quad y'(0)=3.\]
from sympy import *
s=sym.symbols('s')
f=sym.Function('s')
F=sym.laplace_transform(f(t),t,s)
g=sym.cos(t)
G=sym.laplace_transform(g,t,s)
print('Transform of cos(t) is', G[0])
# Define the inverse Laplace transform function
def invL(F):
    return sym.inverse_laplace_transform(F, s, t)
# Transform the equation  and solve for Y=L(y)
eq=Eq((s**2) * F - 2*s - 3 + 4 *s* F -4*( 2) + 3* F -10*G[0],0 )
Y = solve(eq, F)
print('Transform of y is',Y)

# Take the inverse transform
print('y=',invL(Y[0]))
Transform of cos(t) is s/(s**2 + 1)
Transform of y is [(2*s**3 + 11*s**2 + 12*s + 11)/(s**4 + 4*s**3 + 4*s**2 + 4*s + 3)]
y= ((2*sin(t) + cos(t))*exp(3*t) + 2*exp(2*t) - 1)*exp(-3*t)*Heaviside(t)
  1. Find the Laplace Transforms of the following functions:

    • \( f(t)= 3t^2+cos(3t)+12 \)

    • \( f(t)= \dfrac{1}{2}sin(t)+ 5t\)

  2. Find the Inverse Laplace Transforms of the following functions:

    • \( f(t)= \dfrac{7}{s}+ \dfrac{720}{s^7} + \dfrac{1}{(5s^2+\dfrac{1}{5})} \)

    • \( f(t)= \dfrac{2}{2s-1}+\dfrac{72}{s^4} \)

  3. Solve the IVP:

    • \( y'' + 2y'+3y = 9t, \, y(0)=1, \, y'(0)=2 \)