1.6: Solving Linear First Order Differential Equations

Open In Colab

Reading: Notes on Diffy Q’s Section 1.4

A Salt Solution in a Tank


Question 1:


A very large tank initially contains 15 gallons of saltwater containing 6 pounds of salt. Saltwater containing 1 pound of salt per gallon is pumped into the top of the tank at a rate of 2 gallons per minute, while a well-mixed solution leaves the bottom of the tank at a rate of 1 gallon per minute.

Question 1a:


Should the rate of change equation for this situation depend just on the amount of salt \(S\) in the tank, the time \(t\), or both \(S\) and \(t\)? Explain your reasoning.

Solution to Question 1a:







Question 1b:


The following is a general rule of thumb for setting up rate of change equations for situations like this where there is an input and an output:


\[\color{dodgerblue}{\large \text{rate of change } = \text{ rate of change in } - \text{ rate of change out}}.\]


Using the above rule of thumb, figure out a rate of change equation for this situation.

Tip

Think about what the units of \(\dfrac{dS}{dt}\) need to be, where \(S\) is the amount of salt in the tank in pounds.*

Solution to Question 1b:







Plotting Solutions in a Slope Field


We cannot separate the differential equation in Question 1 to find a formula for the solution just yet, but we can use the slope field to approximate solutions graphically.

Recall from Lab 1.2 Slope Fields we introduced the function plot_sol() that we can import from the ode_tools module. See ODE Tools Tutorial for a quick reference guide on using plot_sol() and other functions in the module ode_tools.

Loading ode_tools from GitHub


  • Run the code cell below to load the most up to date modules stored in GitHub.
  • You will only need to run this code cell one time during an active session.
!pip install git+https://github.com/CU-Denver-MathStats-OER/ODEs
from IPython.display import clear_output
clear_output()

Importing the plot_sol() Function


Now that we have loaded the ode_tools module, we are ready to import the plot_sol function by running the code cell below.

from utils.ode_tools import plot_sol

Question 2:


Run the Python code cell below to create slope field for this differential equation you found in Question 1 and plot the solution with initial condition \(S(0)=6\). Based on your plot, estimate the amount of salt in the tank after 15 minutes.

Solution to Question 2:






Enter the formula for the differential equation from Question 1 in place of the ?? in the code cell below. Then run the code and answer the question based on the output.


import numpy as np

# Setup the grid
t = np.linspace(0, 20, 21)  # np.linspace(initial, end, number_values)
S = np.linspace(0, 30, 31)  # np.linspace(initial, end, number_values)

############################################
# STUDENT TO DO:
# Setup the differential equation
# Replace ?? with an appropriate expression
############################################
def diffeq(t, S):
    return ??  # Use t and S for ind and dep variables

# enter initial condition
t0 = 0
S0 = 6

plot_sol(t, S, diffeq, t0, S0)  # Plot solution with initial condition  

First Order Linear Differential Equations


The differential equation you developed for the salty tank is not separable, and therefore using the technique of separation of variables is not appropriate. This equation is a first order linear differential equation , since it can be written in the form

\[ a_1(x) \frac{dy}{dx}+ a_2(x) \cdot y=b(x),\]

where \(a_1(x)\), \(a_2(x)\), and \(b(x)\) are all continuous functions of the independent variable \(x\) alone.

Note if we divide both sides by \(a_1(x)\), we can rewrite any first order linear differential equation in standard form:

\[\frac{dy}{dx} + P(x)y = Q(x).\]

Reversing the Product Rule


The following technique, which we refer to as the reverse product rule, can be used find the general solution to a first-order linear equation.

Question 3:


Review the product rule as you remember it from calculus. In general symbolic terms, how do you represent the product rule? How would you describe it in words?

Solution to Question 3:







Constructing a Method


Consider the differential equation \(\dfrac{dy}{dx}+2y=3\). Note that this is a first order linear differential equation already in standard form, where \(P(x)=2\) and \(Q(x)=3\) are both continuous functions.

The following illustrates a technique for finding the general solution to linear differential equations. The inspiration for the technique comes from a creative use of the product rule and the Fundamental Theorem of Calculus, as well as use of the previous technique of separation of variables.

Step 1:


Use the product rule to expand \((y \mu)'\).


\(\large{ (y \mu)' = ?? }\)






Step 2:


In the equation \(\frac{dy}{dx}+2y=3\), rewrite \(\frac{dy}{dx}\) as \(y'\).


\(\large{ \frac{dy}{dx}+2y=3 \quad \rightarrow \quad \boxed{y' + 2y} = 3 }\)






Step 3:


Notice that the left-hand side of the equation in step 2 looks a lot like the expanded product rule but is missing the function \(\color{dodgerblue}{\mu}\). So multiply both sides by \(\color{dodgerblue}{\mu}\), a function that we will determine shortly.


\(\large{ {\color{dodgerblue}{\mu}}y' + 2y{\color{dodgerblue}{\mu}} = 3{\color{dodgerblue}{\mu}} }\)






Step 4:


Because, so far, \(\color{dodgerblue}{\mu}\) is an arbitrary function, we can have \(\color{dodgerblue}{\mu}\) satisfy any differential equation that we want. Use \(\mu' = 2\mu\) to rewrite the left-hand side of step 3 to look like step 1.


\(\large{ {\color{dodgerblue}{\mu}}y' + {\color{tomato}{??}} = 3{\color{dodgerblue}{\mu}} }\)






Step 5:


Use separation of variables to solve \(\mu' = 2\mu\).






Step 6:


Replace \(\mu\) in the equation from step 3 with your solution from step 5 .






Step 7:


Show that the equation in step 6 can be rewritten as \(\left(ye^{2x}\right)' = 3e^{2x}\).

Tip

Consider step 1.






Step 8:


Write integrals with respect to \(x\) on both sides. Apply the Fundamental Theorem of Calculus.






Step 9:


Obtain an explicit solution by isolating \(y(x)\).






Key Observation


The key is finding a formula for the function \(\mu(x)\) that we multiply on both sides which allowed us to “reverse” the product rule (going from step 6 to step 7). The function \(\color{dodgerblue}{\mu(x)}\) is called the integrating factor.

  • The text Notes of Diffy Q’s uses the notation \(r(x)\) to denote the integrating factor.
  • The notation \(\mu(x)\) for the integrating factor is more commonly used, so we will stick with that notation.

Question 4:


Find a general formula for the integrating factor. Replace the \({\large\color{tomato}{??}}\) in formula in step 1 below with your finding.

Solution to Question 4:




Complete formula in step 1 below.

Summarizing the Steps


  1. Check that the differential equation is first order linear, and rewrite it in standard form: \[ \frac{dy}{dx} + P(x)y = Q(x).\]

  2. Calculate the integrating factor, denoted \(\color{dodgerblue}{\mu(x)}\) using the observation that in general:

\[{\color{dodgerblue}{\mu(x)}} = {\large{\color{tomato}{??}}} \qquad \mbox{(for convenience, set the arbitrary constant $C=0$.)}\]






  1. Multiply both sides of the standard form by \(\color{dodgerblue}{\mu(x)}\), and rewrite the equation as in step 5 of the previous method: \[\frac{d}{dx} \left(y {\color{dodgerblue}{\mu(x)}} \right) = {\color{dodgerblue}{\mu(x)}} Q(x).\]

  2. Integrate both sides with respect to \(x\), and solve for \(y\) (if possible).

\[\int \frac{d}{dx} \left(y {\color{dodgerblue}{\mu(x)}} \right) \ dx = \int {\color{dodgerblue}{\mu(x)}} Q(x) \ dx.\]


\[y {\color{dodgerblue}{\mu(x)}} = \int {\color{dodgerblue}{\mu(x)}} Q(x) \ dx.\]

Question 5:


Use the previous technique, which we refer to as the method of integrating factors or informally the reverse product rule, to find the general solution for the Salty Tank differential equation from Question 1.

Solution to Question 5:







Checking your work to Question 5 with Python:






Complete the Python cells below.


import sympy as sym  # import sympy, we use the abbreviation sym

t, S, C = sym.symbols('t, S, C')  # Creating t, S and C as symbols

S = ??  # enter the symbolic formula for a solution

dS = sym.diff(S,t) # Use diff from sympy library to differentiate y with respect to t

left = (15 + t) * dS  # mult by sides by 15 + t
right = ??  # enter a formula for the right side of diff eq

print("The left side is dS/dt = ", sym.simplify(left), 
      "\n \n The right side is ", sym.simplify(right))

Question 6:


Use your solution to Question 5 to answer the questions below.

Question 6a:


Find the particular solution corresponding to the initial condition \(S(0) = 6\), and then use the particular solution to determine the amount of salt in the tank after 15 minutes. That is, compute \(S(15)\). Your answer should be close to your estimate from Question 2. Is it? If not, you likely made an algebraic error.

Solution to Question 6a:







def sol(t):  # t is independent variable 
    return ??  # enter the formula for S(t)
sol(??)  # evaluate solution at t=15

Question 6b:


What does your solution predict about the amount of salt in the tank in the long run? How about the concentration?

Solution to Question 6b:







Question 6c:


Explain how you can make sense of the predictions from part (b) by using the differential equation itself.

Solution to Question 6c:







Question 7:


Decide whether each differential equation is linear, and if so write it in standard form.

Question 7a:


\(\displaystyle x^2y'=x^2-3y\)

Solution to Question 7a:







Question 7b:


\(\displaystyle 2y \dfrac{dy}{dx} - 3y=8\)

Solution to Question 7b:







Question 8:


Solve the differential equation.

\[z\frac{dw}{dz}+2w=5z^3\]

Solution to Question 8:







Question 9:


Solve the initial value problem.

\[\sin{x} \frac{dy}{dx} + y \cos{x} = x\sin{x}, \quad y \left( \frac{\pi}{2} \right)=2\]

Solution to Question 9:







Creative Commons License Information


Creative Commons License
Exploring Differential Equations by Adam Spiegler is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at https://github.com/CU-Denver-MathStats-OER/ODEs and original content created by Rasmussen, C., Keene, K. A., Dunmyre, J., & Fortune, N. (2018). Inquiry oriented differential equations: Course materials. Available at https://iode.sdsu.edu.