import sympy as sym
from sympy.abc import s,t
# Just run this code cell. Do Not Edit.
# Define the Laplace transform function
def L(f):
return sym.laplace_transform(f, s, t)
# Define the inverse Laplace transform function
def invL(F):
return sym.inverse_laplace_transform(F, s, t)
4.4: Solving ODEs with Laplace Transforms
Reading: Notes on Diffy Q’s Section 6.2
Steps for Solving ODE’s with Laplace Transforms:
Let’s focus our exploration with Laplace transforms on their application to differential equations. We can apply the Laplace transform to solve differential equations with a frequently used problem solving strategy:
Step 1: Transform a difficult problem into an easier one.
Step 2: Solve the easier problem.
Step 3: Use the previous solution to obtain a solution to the original problem.
We will walk through each step to solve the differential equation
\[\color{dodgerblue}{y''-2y'+5y=0 \quad \mbox{with} \quad y(0)=2 \mbox{ and } y'(0)=4}.\]
Step 1: Transform a difficult problem into an easier one.
- Apply the Laplace transform of both sides of the differential equation.
- Refer to Table of Common Laplace Transforms in Appendix A and Properties in Appendix B.
- The function
sympy.laplace_transform(f,t,s)
may be useful in some cases. - The initial conditions for \(y(0)\) and \(y'(0)\) will be important.
\[\begin{array}{rcll} \mathscr{L} \left\{ y''-2y'+5y \right\} &=& \mathscr{L} \left\{ 0 \right\} & {\color{tomato}{\mbox{Apply $\mathscr{L}$ to both sides.}}} \\ \mathscr{L} \left\{ y'' \right\} -2\mathscr{L} \left\{y'\right\} + 5 \mathscr{L} \left\{ y \right\} &=& \mathscr{L} \left\{ 0 \right\} & {\color{tomato}{\mbox{Applying properties 1 and 2 on left side.}}}\\ \mathscr{L} \left\{ y'' \right\} -2\mathscr{L} \left\{y'\right\} + 5 Y(s) &=& 0 & {\color{tomato}{\mbox{a. justification ??}}}\\ \big( s^2Y(s)-sy(0)-y'(0) \big) - 2 \big( sY(s) - y(0) \big) + 5 Y(s) &=& 0 & {\color{tomato}{\mbox{b. justification ??}}}\\ \big( s^2Y(s)-2s-4 \big) - 2 \big( sY(s) - 2 \big) + 5 Y(s) &=& 0 & {\color{tomato}{\mbox{c. justification ??}}}\\ \end{array} \]
Question 1:
Justify each of the steps labeled a, b and c in the work above.
Solution to Question 1:
??
??
??
Step 2: Solve the easier problem.
- Rearrange and group like terms.
- Then solve for \(Y(s)\).
\[\begin{array}{rcll} \big( s^2Y(s)-2s-4 \big) - 2 \big( sY(s) - 2 \big) + 5 Y(s) &=& 0 & {\color{tomato}{\mbox{Result from Step 1}}}\\ \big( s^2Y(s) - 2sY(s) +5Y(s) \big) - 2s &=& 0 & {\color{tomato}{\mbox{a. justification ??}}}\\ (s^2 - 2s +5)Y(s) &=& 2s & {\color{tomato}{\mbox{b. justification ??}}}\\ Y(s) &=& \dfrac{2s}{s^2-2s+5} & {\color{tomato}{\mbox{c. justification ??}}}\\ \end{array}\]
Question 2:
Justify each of the steps labeled a, b and c in the work above.
Solution to Question 2:
??
??
??
Step 3: Use the previous solution to obtain a solution of the original problem.
- Take the inverse Laplace transform and solve for \(y(t) = \mathscr{L}^{-1}\{Y(x) \}\).
- The function
sympy.inverse_laplace_transform(F,s,t)
will be helpful!
A solution to the original differential equation is a function \(y(t)\) whose Laplace transform is \(Y(s)\) from Step 2. Thus we apply the inverse Laplace transfrom to the result from Step 2 and solve for \(y(t)\).
\[\begin{array}{rcll} \mathscr{L}^{-1} \left\{ Y(s) \right\} &=& \mathscr{L}^{-1} \left\{ \dfrac{2s}{s^2-2s+5} \right\} & {\color{tomato}{\mbox{Applying $\mathscr{L}^{-1}$ to both sides.}}}\\ y(t) &=& \mathscr{L}^{-1} \left\{ \dfrac{2s}{(s-1)^2 + 4} \right\} & {\color{tomato}{\mbox{a. justification ??}}}\\ y(t) &=& 2 \mathscr{L}^{-1} \left\{ \dfrac{s}{(s-1)^2 + 4} \right\} & {\color{tomato}{\mbox{b. justification ??}}}\\ y(t) &=& 2 \mathscr{L}^{-1} \left\{ \dfrac{s-1+1}{(s-1)^2 + 4} \right\} & {\color{tomato}{\mbox{c. justification ??}}}\\ y(t) &=& 2 \mathscr{L}^{-1} \left\{ \dfrac{s-1}{(s-1)^2 + 4} + \dfrac{1}{(s-1)^2 + 4} \right\} & {\color{tomato}{\mbox{d. justification ??}}}\\ y(t) &=& 2 \mathscr{L}^{-1} \left\{ \dfrac{s-1}{(s-1)^2 + 4} \right\} + 2 \mathscr{L}^{-1} \left\{ \dfrac{1}{(s-1)^2 + 4} \right\} & {\color{tomato}{\mbox{e. justification ??}}}\\ y(t) &=& 2 \mathscr{L}^{-1} \left\{ \dfrac{s-1}{(s-1)^2 + 4} \right\} + \mathscr{L}^{-1} \left\{ \dfrac{2}{(s-1)^2 + 4} \right\} & {\color{tomato}{\mbox{f. justification ??}}}\\ y(t) &=& 2e^t\cos{(2t)}+ e^t\sin{(2t)} & {\color{tomato}{\mbox{g. justification ??}}}\\ \end{array}\]
Question 3:
Justify each of the steps labeled a to g in the work above.
Solution to Question 3:
??
??
??
??
??
??
??
Question 4:
In Questions 1, 2, and 3 we apply the Laplace transform to solve the differential equation
\[y''-2y'+5y=0 \quad \mbox{with} \quad y(0)=2 \mbox{ and } y'(0)=4,\]
and we discovered the solution
\[y(t) = 2e^t\cos{(2t)}+ e^t\sin{(2t)}.\]
Question 4a:
What other method(s) for solving differential equations could we use to solve this differential equation?
Solution to Question 4a:
Question 4b:
Based on your answer to part a, explain why the form of the solution is not surprising.
Solution to Question 4b:
Question 4c:
What are some of the pros and cons of using the Laplace transforms to solve the differential equation compared to the method you identified in part a?
Solution to Question 4c:
Solving ODE’s with Laplace Transforms and SymPy
As you may have gathered, using the Laplace transform to solve differential equations may present some challenges at each step. In particular, finding the inverse Laplace transform of \(Y(s)\) in the last step involved the most work. We can use the built-in Laplace transform functions in SymPy
to help with some of the work.
- For a review of Laplace transforms using
sympy.laplace_transform_(f,t,s)
, see the section on Computing Laplace Transforms in Python from Worksheet 20. - For a review of inverse Laplace transforms using
sympy.inverse_laplace_transform(F,s,t)
, see the section on Inverse Laplace Transforms withSymPy
from Worksheet 22.
Below are a couple of additional resources for help with Laplace transforms with SymPy
.
- For official documentation, see SymPy Doc
- Here is another helpful resource.
Defining Laplace and Inverse Laplace Transform Functions:
Run the code cell below to define the Laplace transform function L(f)
and inverse Laplace transform function invL(F)
.
Question 5:
In Question 3, you explain the algebra and properties of inverse Laplace transforms applied in Step 3 of solving a differential equation with the Laplace transform. Below is a recap of the result.
What is a function \(y(t)\) whose Laplace tranform is \(Y(s) = \dfrac{2s}{s^2-2s+5}\)?
\[\begin{array}{rcl} \mathscr{L}^{-1} \left\{ Y(s) \right\} &=& \mathscr{L}^{-1} \left\{ \dfrac{2s}{s^2-2s+5} \right\} \\ \vdots & = & \vdots \\ y(t) &=& 2e^t\cos{(2t)}+ e^t\sin{(2t)}\\ \end{array}\]
Edit the code cell below to use SymPy
to solve for \(y(t)\) and verify the previous answer. Be sure you first run the previous code cell to import SymPy
and Laplace transform functions.
Solution to Question 5:
Edit the code cell below.
#############################################################
# STUDENT TO DO:
# Replace the ?? with an approrpriate expression
#############################################################
= # define your function Y(s) with respect to s
F
# Solve for y(t) invL(F)
Question 6: Checking Your Answer in Python
We applied Laplace transforms to solve the differential equation
\[y''-2y'+5y=0 \quad \mbox{with} \quad y(0)=2 \mbox{ and } y'(0)=4,\]
and we discovered the solution
\[y(t) = 2e^t\cos{(2t)}+ e^t\sin{(2t)}.\]
Edit the code cell below to use SymPy
to plug \(y(t)\) into the differential equation to verify it satisfies the differential equation.
Solution to Question 6:
Edit the code cell below.
#############################################################
# STUDENT TO DO:
# Replace the ?? with an approrpriate expression
#############################################################
= ??
y
= y.diff(t, 1) # compute y'
dy = y.diff(t, 2) # compute y''
ddy
#############################################################
# STUDENT TO DO:
# Replace the ?? with an approrpriate expression
#############################################################
= sym.simplify(??)
left = 0
right
#############################################################
# Check initial conditions
#############################################################
= y.evalf(subs={t:0})
y0 = dy.evalf(subs={t:0})
prime0
print("The left side is ", left,
"\n \n The right side is ", right,
"\n \n y(0) = ", y0,
"\n \n y'(0) = ", prime0)
Question 7:
Solve the initial value problem using the Laplace Transform. You may use Python as much (or as little) as you like.
\[y''-y'-2y=0 \quad \mbox{with} \quad y(0)=-2 \mbox{ and } y'(0)=5.\]
Solution to Question 7:
It is recommended to do some work by hand and use Python to help with part of the process. Feel free to add some Python code cells below.
Question 8:
Solve the initial value problem using Laplace Transforms. You may use Python as much (or as little) as you like.
\[y''-4y'-5y=4e^{3t} \quad \mbox{with} \quad y(0)=2 \mbox{ and } y'(0)=7.\]
Solution to Question 8:
It is recommended to do some work by hand and use Python to help with part of the process. Feel free to add some Python code cells below.
Question 9:
Solve the initial value problem using Laplace Transforms. You may use Python as much (or as little) as you like.
\[ty''-ty'+y=2 \quad \mbox{with} \quad y(0)=2 \mbox{ and } y'(0)=-1.\]
Solution to Question 9:
It is recommended to do some work by hand and use Python to help with part of the process. Feel free to add some Python code cells below.
Question 10:
Solve the initial value problem using Laplace Transforms. You may use Python as much (or as little) as you like.
\[y''+ty'-y=0 \quad \mbox{with} \quad y(0)=0 \mbox{ and } y'(0)=3.\]
Solution to Question 10:
It is recommended to do some work by hand and use Python to help with part of the process. Feel free to add some Python code cells below.
Appendix A: Common Laplace Transforms
\(\displaystyle \large f(t)\) | \(\displaystyle \large F(s) = \mathscr{L} \left\{ f(t) \right\}\) |
---|---|
\(\displaystyle \large f(t)=1\) | \(\displaystyle \large F(s)=\frac{1}{s}, \ s > 0\) |
\(\displaystyle\large f(t)=e^{at}\) | \(\displaystyle \large F(s) = \frac{1}{s-a}, \ s > a\) |
\(\displaystyle \large f(t)=t^n, \ n=1,2, \ldots\) | \(\displaystyle \large F(s) = \frac{n!}{s^{n+1}}, \ s > 0\) |
\(\displaystyle \large f(t)=\sin{(bt)}\) | \(\displaystyle \large F(s) = \frac{b}{s^2+b^2}, \ s > 0\) |
\(\displaystyle \large f(t)=\cos{(bt)}\) | \(\displaystyle \large F(s) = \frac{s}{s^2+b^2}, \ s > 0\) |
\(\displaystyle \large e^{at}t^n, \ n=1,2, \ldots\) | \(\displaystyle \large F(s) = \frac{n!}{(s-a)^{n+1}}, \ s > a\) |
\(\displaystyle \large e^{at}\sin{(bt)}\) | \(\displaystyle \large F(s) = \frac{b}{(s-a)^2+b^2}, \ s > a\) |
\(\displaystyle \large e^{at}\cos{(bt)}\) | \(\displaystyle \large F(s) = \frac{s-a}{(s-a)^2+b^2}, \ s > a\) |
Appendix B: Properties of Laplace Transforms
1. \(\color{dodgerblue}{\mathscr{L} \left\{ cf(t) \right\} = c \mathscr{L} \left\{ f(t) \right\}}\), where \(c\) is a constant.
2. \(\color{dodgerblue}{\mathscr{L} \left\{ f_1(t) + f_2(t) \right\} = \mathscr{L} \left\{ f_1(t) \right\} + \mathscr{L} \left\{ f_2(t)\right\}}\).
3. If \(F(s) = \mathscr{L} \left\{ f(t) \right\}\) exists for all \(s > \alpha\), then \(\color{dodgerblue}{\displaystyle \mathscr{L} \left\{ e^{at} f(t) \right\} = F(s-a)}\) for all \(s>\alpha + a\).
4. If \(F(s) =\mathscr{L} \left\{ f(t) \right\}\) exists for all \(s > \alpha\), then for all \(s>\alpha\),
\[\color{dodgerblue}{\mathscr{L} \left\{ f^{(n)}(t) \right\} = s^n \mathscr{L} \{ f(t) \}-s^{n-1} f(0)- s^{n-2} f'(0) - \ldots - f^{(n-1)}(0)}.\]
5. If \(F(s) =\mathscr{L} \left\{ f(t) \right\}\) exists for all \(s > \alpha\), then
\[\color{dodgerblue}{\mathscr{L} \left\{ t^n f(t) \right\} = (-1)^n \frac{d^nF}{ds^n} \mbox{ for all } s > \alpha}.\]
Creative Commons License Information
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.