Showing posts with label Laplace transforms. Show all posts
Showing posts with label Laplace transforms. Show all posts

Saturday, May 20, 2023

Casio Classpad fx-CP400: Solving a System of Linear Differential Equations Using Laplace Transforms

Casio Classpad fx-CP400: Solving a System of Linear Differential Equations Using Laplace Transforms



Introduction


The following procedure should work with the Casio Classpad family of calculators (300, 330, fx-CP400, fx-CP500). 


An attempt to use the Casio Classpad to solve the system of differential equations:


dxf/dt = A * xf(t) + B * yf(t) + g1(t)

dyf/dt = C * xf(t) + D * yf(t) + g2(t)


Initial conditions:  xf(0) = xf0,   yf(0) = yf0



The independent variable in all the functions is t.  The Casio Classpad's CAS functions laplace and invLaplace are used to accomplish this task.



Syntax


Laplace Transform of f(t):


laplace(f(t), t, s)


Laplace Transform of a Differential Equation:


laplace(diff eq, independent variable, dependent variable, s)


Inverse Laplace Transformation:


invLaplace(ℒ(s), s, t)


t:  parameter of the original function f(t)

s:  parameter of the transformed function ℒ(s)


The definition of a Laplace Transformation:


ℒ(f(t))(s) = ∫( f(t) * e^(-s*t) dt, t = 0 to ∞)


Now, even though we are working a system of differential equations, the laplace and invLapace commands can only work on function at a time.  Any other variable will be treated as a constant, even it was meant to represent another functions.  The substitution steps will account for this.  


The variables used to respect the Classpad's system variables.  


Here are the steps I used to solve:


dxf/dt = A * xf(t) + B * yf(t) + g1(t)

dyf/dt = C * xf(t) + D * yf(t) + g2(t)


Initial conditions:  xf(0) = xf0,   yf(0) = yf0


Spaces are added to readability.  



1.  Store dxf/dt in the variable f1.   Use xf' to represent dxf/dt.  


2.  Store dyf/dt in the variable f2.   Use yf' to represent dyf/dt.


3.  Execute the following and substitutions:


laplace( f1, t, xf, s ) ⇒ g1

g1 | xf(0) = xf0 and  yf / s = Mp ⇒ g1


4.  Execute the following and substitutions:


laplace( f2, t, yf, s ) ⇒ g2

g2 | yf(0) = yf0 and Lp = Mp ⇒ g2

g2 | xf /s = Lp ⇒ g2


Note Lp = ℒ( xf(t) ) and Mp = ℒ( yf(t) )


5.  Now solve the system of transformed equations: 


solve( {g1, g2}, {Lp, Mp} ) ⇒ lists


6.  Take the inverse laplace transforms:


invLaplace( getRight( lists[1], s, t ) ) ⇒ h1

invLaplace( getRight( lists[2], s, t ) ) ⇒ h2


The solutions are:


xf(t) = h1

yf(t) = h2


The getRight command extracts the right side of an equation.



Examples


Example 1:


xf ' = -0.08 * xf + 0.02 * yf + 6

yf ' = 0.08 * xf - 0.08 * yf


Initial conditions:  xf(0) = 0, yf(0) = 150






Example 2:


xf ' = 2 * xf + yf + t^2

yf ' = -2 * xf + 5


Initial conditions:  xf(0) = 2, yf(0) = 5




Casio Classpad Program:  laplaced


Download here:  https://drive.google.com/file/d/1zxTEynCjXmBrPU9pYqmXo3kF_so7fiI-/view?usp=share_link


Code:


' setup

SetRadian


' local variables

Local str1, str2, f1, f2

Local g1, g2, lists, h1, h2

Local Mp, Lp, t, s, xval, yval


' main

ClrText

InputStr str1, "xf'(xf,yf,g1(t))="

InputStr str2, "yf'(xf,yf,g2(t))="

Input xval, "xf(0)? "

Input yval, "yf(0)? "


StrJoin "xf'=", str1, str1

StrJoin "yf'=", str2, str2

strToExp(str1) ⇒ f1

strToExp(str2) ⇒ f2


' transform and solve

laplace(f1, t, xf, s) ⇒ g1

g1 | xf(0) = xval and yf/s = Mp ⇒ g1


laplace(f2, t, yf, s) ⇒ g2

g2 | yf(0) = yval and Lp = Mp ⇒ g2

g2 | xf/s = Lp ⇒ g2


Print "Laplace Transforms:"

PrintNatural g1

Print g1

PrintNatural g2

Print g2


solve({g1, g2},{Lp, Mp})⇒lists

invLaplace(getRight(lists[1]),s,t) ⇒ h1

invLaplace(getRight(lists[2],s,t) ⇒ h2


Print "Solutions: "

Print "xf = "

PrintNatural h1

Print h1

Print "yf = "

PrintNatural h2

Print h2


Note:  PrintNatural displays the expression in textbook form in a popup box, but it does not add anything to the text output terminal.  This is why I included both PrintNatural and Print commands.  



Source


Kreyszig, Erwin.  Advanced Engineering Mathematics  8th Edition  John Wiley & Sons, Inc:  New York, NY.  1999.  ISBN 0-471-15496-2



All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 

Saturday, April 1, 2023

TI-84 Plus CE and Numworks: System of Linear Differential Equations (Simple System)

TI-84 Plus CE and Numworks: System of Linear Differential Equations (Simple System) 



Solving  The System


The program presented today will solve the following system of equations:


dx/dt = A * x(t) + B * y(t)

dy/dt = C * x(t) + D * y(t)

with initial conditions x(0) = x0 and y(0) = y0


The formulas used in the program are derived using the Laplace Transform.


dx/dt = A * x(t) + B * y(t)

dy/dt = C * x(t) + D * y(t)


Laplace Transforms to be used:

ℒ{f(t)} = F(s)

ℒ{df/dt} = s * F(s) - f(0)


Apply the Laplace Transform transform:


s * X(s)  - x0 = A * X(s) + B * Y(s)

s * Y(s) - y0 = C * X (s) + B * Y(s)


(s - A) * X(s) + (-B) * Y(s) = x0

(-C) * X(s) + (s - D) * Y(s) = y0


Define three matrices:


Md = [ [ s - A, -B ], [ -C, s - D ] ]


where

det(Md) = s^2 - (A + D) * s + (A * D - B * C)


which can be factored into:

(s - P) * (s - Q)


where:

P = (( A + D ) + √(( A + D)^2 - 4 * (A * D - B * C)) /2

Q = (( A + D ) - √(( A + D)^2 - 4 * (A * D - B * C)) /2


Mx = [ [ x0, -B ], [ y0, s - D ] ] 


where

det(Mx) = x0 * (s - D) + B * y0



My = [ [ s - A, x0 ], [ - C, y0 ] ]


where 

det(My) = (s - A) * y0 + C * x0


Per Cramer's Rule, the solution to X(s) and Y(s) are:


X(s) = det(Mx) / det(Md)


Y(s) = det(My) / det(Md)


What happens next depends of the roots P and Q.  We're assuming that P and Q are real here but the situation applies if P and Q are complex. 



If P ≠ Q:


If P ≠ Q, then after simplifying and finding partial fractions:


X(s) = ( x0 * (s - D) + B * y0 ) / ((s - P) * (s - Q)) = α / (s - P) + β / (s - Q)


where

α = ( B * y0 + (P - D) *x0) / (P - Q)

β = x0 - α


Y(s) = ( (s - A) * y0 + C * x0 ) / ((s - P) * (s - Q)) = γ / (s - P) + δ / (s - Q)


where

γ =(C * x0 + y0 * (P - A)) / (P - Q)

δ = y0 - γ


Applying the inverse Laplace transform:


x(t) = α * e^(P * t) + β * e^(Q * t)

y(t) = γ * e^(P * t) + δ * e^(Q * t)



If P = Q:


If P = Q, then after simplifying and finding partial fractions:


X(s) = ( x0 * (s - D) + B * y0 ) / (s - P)^2 = α / (s - P)^2 + β / (s - Q)


where

α = B * y0 + (P - D) * x0 

β = x0


Y(s) = ( (s - A) * y0 + C * x0 ) / (s - P)^2 = γ / (s - P)^2 + δ / (s - Q)


where

γ =C * x0 + y0 * (P - A)

δ = y0


Applying the inverse Laplace transform:


x(t) = α * t * e^(P * t) + β * e^(Q * t)

y(t) = γ * t * e^(P * t) + δ * e^(Q * t)




TI-84 Plus CE Program:  LINSYS1


Download the program here:  https://drive.google.com/file/d/14zYpT4xhLRGVvBNriOacIOGBpqXLWswR/view?usp=share_link


Program Listing:


Radian

a+bi

ClrHome

Disp "DX/DT=AX+BY DY/DT=CX+DY"

Prompt A,B,C,D

Input "X0? ",M

Input "Y0? ",N

((A+D)+√((A+D)²-4*(A*D-B*C)))/2→P

((A+D)-√((A+D)²-4*(A*D-B*C)))/2→P


If P≠Q

Then

(B*N-D*M+P*M)/(P-Q)→R

M-R→S

(C*M-A*N+P*N)/(P-Q)→U

N-U→V

ClrHome

Output(2,1,"X=Re^(PT)+Se^(QT)")

Output(3,1,"R= "+toString(R))

Output(4,1,"P= "+toString(P))

Output(5,1,"S= "+toString(S))

Output(6,1,"Q= "+toString(Q))

Pause

ClrHome

Output(2,1,"Y=Ue^(PT)+Ve^(QT)")

Output(3,1,"U= "+toString(U))

Output(4,1,"P= "+toString(P))

Output(5,1,"V= "+toString(V))

Output(6,1,"Q= "+toString(Q))

Pause

Else

B*N-D*M+M*P→P

M→S

C*M-A*N+N*P→U

N→V

ClrHome

Output(2,1,"X=RTe^(PT)+Se^(PT)")

Output(3,1,"R= "+toString(R))

Output(4,1,"P= "+toString(P))

Output(5,1,"S= "+toString(S))

Pause

ClrHome

Output(2,1,"Y=UTe^(PT)+Ve^(PT)")

Output(3,1,"U= "+toString(U))

Output(4,1,"P= "+toString(P))

Output(5,1,"V= "+toString(V))

Pause

End

ClrHome



Python:  dfsys1.py


Link from my Numworks page:  https://my.numworks.com/python/ews31415/dfsys1


Modules: 

cmath:  complex math

mathplotlib.pyplot:  screen plotting and text placement


Script listing:  


from cmath import *

from matplotlib.pyplot import *

# 2023-01-28 EWS


# parameter input

print("systems of differential\nequations")

print("dx/dt=a*x+b*y")

print("dy/dt=c*x+d*y")

a=float(input("a? "))

b=float(input("b? "))

c=float(input("c? "))

d=float(input("d? "))

m=float(input("x0? "))

n=float(input("y0? "))



# characteristic roots

p=((a+d)+sqrt((a+d)**2-4*(a*d-b*c)))/2

q=((a+d)-sqrt((a+d)**2-4*(a*d-b*c)))/2


# set up result screen

axis((0,10,0,10))

axis("off")


# determine solutions

# best used for real solutions

if p!=q:

  r=(b*n+m*(p-d))/(p-q)

  s=m-r

  u=(c*m+n*(p-a))/(p-q)

  v=n-u

  text(0,9,"x=re**(pt)+se**(qt)")

  text(0,8.5,"r="+str(r))

  text(0,8,"p="+str(p))

  text(0,7.5,"s="+str(s))

  text(0,7,"q="+str(q))

  text(0,6,"y=ue**(pt)+se**(vt)")

  text(0,5.5,"u="+str(u))

  text(0,5,"p="+str(p))

  text(0,4.5,"v="+str(v))

  text(0,4,"q="+str(q))

else:

  r=(b*n+m*(p-d))

  s=m

  u=(c*m+n*(p-a))

  v=n

  text(0,9,"x=rte**(pt)+se**(pt)")

  text(0,8.5,"r="+str(r))

  text(0,8,"p="+str(p))

  text(0,7.5,"s="+str(s))

  text(0,6,"y=ute**(pt)+se**(vt)")

  text(0,5.5,"u="+str(u))

  text(0,5,"p="+str(p))

  text(0,4.5,"v="+str(v))


show()



Examples


Example 1


dx/dt = 3 * x(t) - 2 * y(t)

dy/dt = 2 * x(t) - 2 * y(t)

x(0) = 6, y(0) = 9


Solutions:

x(t) = 2 * e^(2*t) + 4 * e^(-t)

y(t) = e^(2*t) + 8 * e^(-t)


Example 2


dx/dt = 3 * x(t) - 4 * y(t)

dy/dt = x(t) - y(t)

x(0) = 1, y(0) = 0


Solutions:

x(t) = 2 * t * e^(t) + e^(t)

y(t) = t * e^(t) 



Eddie 


All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Saturday, January 8, 2022

Working with Laplace Transforms

Working with Laplace Transforms


Using Laplace Transforms to solve various differential equations


Table of Laplace Transforms

Function:  y(t)
Transformed Function:  f(s)

f(s) = ℒ( y(t) )
= ∫ y(t) ∙ exp(-s ∙ t) dt from t = 0 to t = ∞,  s is a complex number

a1, a2, and a are constants

ℒ( a1 ∙ y1(t) + a2 ∙ y2(t) ) = a1 ∙ f1(s) + a2 ∙f2(s)

ℒ ( y'(t) ) = s ∙ f(s) - y(0)

ℒ( t ∙ y(t) ) = -f'(s)

ℒ( 1 ) = 1 ÷ s

ℒ( a ) = a ÷ s

ℒ( t^n ) = n! ÷ (s^(n+1))

ℒ( t^n ÷ n! ) = 1 ÷ (s^(n+1))

ℒ( e^(a ∙ t) ) = 1 ÷ (s - a)

ℒ( sin(a ∙ t) ) = a ÷ (s^2 + a^2)

ℒ( cos(a ∙ t) ) = s ÷ (s^2 + a^2)


All the problems presented today will have the initial condition y(0) = 0.  



Problem 1:  y'(t) + a ∙ y(t) = b with y(0) = 0


Note: y'(t) = dy/dt.   All of the problems this weekend will have an initial condition.

 y'(t) + a ∙ y(t) = b

Applying the Laplace Transform:

s ∙ f(s) - y(0) + a ∙ f(s) = b ÷ s

f(s) ∙ (s + a) = b ÷ s

f(s) = b ÷ (s ∙ (s + a))



Partial fractions:

b ÷ (s ∙ (s + a)) = G ÷ s + H ÷ (s + a)

Simplifying and considering the numerator:

b + 0 ∙ s = a ∙ G + s ∙ (G + H)

Then:

b = a ∙ G
0 = G + H

G = b/a,  H = -G, H = -b/a


f(s) = (b/a) ÷ s - (b/a) ÷ (s + a)

Reverse the Laplace Transform:

y(t) = b/a - b/a ∙ e^(a ∙ t)

y(t) = b/a ∙ (1 - e^(a ∙ t))



Problem 2:  y'(t) + a ∙ y(t) = e^(b ∙ t) with y(0) = 0

y'(t) + a ∙ y(t) = e^(b ∙ t)

Applying the Laplace Transform:

s ∙ (f(s) - y(0) + a ∙ f(s) = 1 ÷ (s - b)

(s + a) ∙ f(s) = 1 ÷ (s - b)

f(s) = 1 ÷ ((s - b) ∙ (s + a))


Partial fractions:

1 ÷ ((s - b) ∙ (s + a)) = E ÷ (s - a) + F ÷ (s + a)

Simplifying and considering the numerator:

1 = E ∙ (s + a) + F ∙ (s - b)

0 ∙ t + 1 = E ∙ (s + a) + F ∙ (s - b)

Solving for E and F:

1 = a ∙ E - b ∙ F
0 = E + F

E = -F;  F = -1 ÷ (a + b), E = 1 ÷ (a + b)


f(s) = (1/(a + b)) ÷ (s - b) - (1/(a - b)) ÷ (s + a)

Reverse the Laplace Transform:

y(t) = e^(b ∙ t) ÷ (a + b) - e^(-a ∙ t) ÷ (a + b)

y(t) = (e^(b ∙ t) - e^(-a ∙ t)) ÷ (a + b)



Problem 3:  y'(t) + a ∙ y(t) = b ∙ t + c with y(0) = 0


y'(t) + a ∙ y(t) = b ∙ t + c

Applying the Laplace Transform:

s ∙ f(s) - y(0) + a ∙ f(s) = (b ∙ 1!) ÷ (s^(1 + 1)) + c ÷ s

s ∙ f(s) + a ∙ f(s) = b ÷ s^2 + c ÷ s

f(s) = (b + c ∙ s) ÷ (s^2 ∙ (s + a))


Partial fractions:

(b + c ∙ s) ÷ (s^2 ∙ (s + a)) = G ÷ (s + a) + (s ∙ H + J) ÷ s^2

= G ÷ (s + a) + H ÷ s + J ÷ s^2

Simplifying and considering the numerator:
 
b + c ∙ s + 0 ∙ s^2  = G ∙ s^2 + H ∙ s^2 + H ∙ a ∙ s + J ∙ s + J ∙ a

b = a ∙ J
c = a ∙ H + J
0 = G + H

H = -G; J = b/a, H = (a ∙ c - b) ÷ a^2, G = (b - a ∙ c) ÷ a^2


f(s) = ((b - a ∙ c) ÷ a^2) ÷ (s + a) + ((a ∙ c - b) ÷ a^2) ÷ s + (b/a) ÷ s^2

Reverse the Laplace Transform:

y(t) = ((b - a ∙ c) ÷ a^2) ∙ e^(-a ∙ t) + ((a ∙ c - b) ÷ a^2)  + (b/a) ∙ t





Problem 4:  y'(t) + a ∙ y(t) = b ∙ t^2 with y(0) = 0


y'(t) + a ∙ y(t) = b ∙ t^2

Applying the Laplace Transform:

s ∙ f(s) - y(0) + a ∙ f(s) = 2 ∙ b ÷ s^3

f(s) = (2 ∙ b) ÷ (s^3 ∙ (s + a))


Partial fractions:

(2 ∙ b) ÷ (s^3 ∙ (s + a)) = (F ∙ s^2 + G ∙ s + H) ÷ s^3 + K ÷ (s + a)

(2 ∙ b) ÷ (s^3 ∙ (s + a)) = F ÷ s + G ÷ s^2 + H ÷ s^3 + K ÷ (s + a)

Simplifying and considering the numerator:

0 ∙ s^3 + 0 ∙ s^2 + 0 ∙ s + 2 ∙ b = F ∙ s^3 + G ∙ s^2 + H ∙ s + F ∙ a ∙ s^2 + G ∙ a ∙ s + H ∙ a + K ∙ s^3

2 ∙ b = a ∙ H
0 = H + a ∙ G
0 = G + a ∙ F
0 = F + K

F = -K; K = (-2 ∙ b) ÷ a^3 ; F = (2 ∙ b) ÷ a^3; H = (2 ∙ b) ÷ a; G = (-2 ∙ b) ÷ a


f(s) = (2 ∙ b)/a^3 ÷ s - (2 ∙ b)/a^2 ÷ s^2 + (2 ∙ b)/a ÷ s^3 - (2 ∙ b)/a^3 ÷ (s + a)

I use Wolfram Alpha and CAS calculators to help verify whether the work is done correctly.  Sometimes I have deal with problems in parts.  

Reverse the Laplace Transform:

y(t) = (2 ∙ b)/a^3 - (2 ∙ b)/a^2 ∙ t + (b/a) ∙ t^2 - (2 ∙ b)/a^3 ∙ e^(-a ∙ t)

Note:  ℒ( t^n ÷ n! ) = 1 ÷ (s^(n+1)), ℒ( t^2 ÷ 2) = 1 ÷ (s^2)


Eddie



All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Monday, August 19, 2013

Differential Equations #7: Laplace Transforms and Systems of Differential Equations

In this blog we will look at how Laplace transforms assist us in solving systems of differential equations.

In the examples tonight, I have design the y(x) and z(x) as the equations to solve for, and designate:

L(y) = F(s) (which I will shorten to F)
L(y') = s*F - y(0)

L(z) = G(s) (which I will shorten to G)
L(z') = s*G - z(0)


As a reference:
L( f(t) ) → F(s)
1 → 1/s
t^n → n!/(s^(n+1))
e^(a*t) → 1/(s-a)
sin(a*t) → a/(s^2 + a^2)
t*sin(a*t) → (2*a*s)/((s^2 + a^2)^2)
cos(a*t) → s/(s^2 + a^2)
t*cos(a*t) → (s^2 - a^2)/((s^2 + a^2)^2)
sinh(a*t) → a/(s^2-a^2)
cosh(a*t) → s/(s^2-a^2)
e^(a*t)*sin(b*t) → b/((s-a)^2 + b^2)
e^(a*t)*cos(b*t) → (s-a)/((s-a)^2 + b^2)
e^(a*t)*sinh(b*t) → b/((s-a)^2 - b^2)
e^(a*t)*cosh(b*t) → (s-a)/((s-a)^2 - b^2)


For this, it would be best to show how to solve systems by example.

Examples:

1. y' = 2*y + z
z' = -2y
Initial Conditions: y(0)=1, z(0)=-1


Using the transforms above, the result is:
s*F - 1 = 2*F + G
s*G + 1 = -2*F

-1 = (2-s)*F + G
1 = -2*F - s*G

Solving for F and G:

F = (s-1)/(s^2 - 2*s + 2)
G = (-s)/(s^2 - 2*s + 2)

Taking inverse Laplace Transforms for both F and G:

F = (s-1)/(s^2 - 2*s + 2)
F = (s-1)/(s^2 - 2*s + 1 + 1)
F = (s-1)/((s-1)^2 + 1)
L⁻¹(F) = y = e^x * cos x

G = (-s)/(s^2 - 2*s + 2)
G = (-s)/((s - 1)^2 + 1)
G = (-s - 1 + 1)/((s-1)^2 + 1)
G = -(s - 1)/((s-1)^2 + 1) - 1/((s-1)^2 + 1)
L⁻¹(G) = z = -e^-x * cos x - e^x * sin x

y = e^x * cos x
z = -e^-x * cos x - e^x * sin x

2. y' + z = x
z' + 4*y = 0
Initial Conditions: y(0)=1, z(0)=-1


L(x) = 1/s^2

Then:
s*F - 1 + G = 1/s^2
s*G + 1 + 4*F = 0

s*F + G = 1/s^2 + 1
4 * F + s*G = -1

F = (s^2 + s + 1)/(s^3 - 4*s)
G = (-s^3 - 4*s^2 - 4)/(s^4 - 4*s^2)

Finding y and z:

F = (s^2 + s + 1)/(s^3 - 4*s)
F = -1/4 * 1/s + 3/8 * 1/(s+2) + 7/8 * 1/(s-2)
L⁻¹(F) = y = -1/4 + 3/8 * e^(-2x) + 7/8 * e^(2x)

G = (-s^3 - 4*s^2 - 4)/(s^4 - 4*s^2)
G = 1/s^2 + 3/4 * 1/(s + 2) - 7/4 * 1/(s-2)
L⁻¹(G) = z = x + 3/4 * e^(-2*x) - 7/4 * e^(2*x)

y = -1/4 + 3/8 * e^(-2x) + 7/8 * e^(2x)
z = x + 3/4 * e^(-2*x) - 7/4 * e^(2*x)

3. y' + z' = 3
y - z = x
Initial Conditions: y(0) = 1, z(0) = 0


s*F - 1 + s*G = 3/s
F - G = 1/s^2

F = (s + 4)/(2*s^2)
F = s/(2*s^2) + 4/(2*s^2)
F = 1/(2*s) + 2/(s^2)
L⁻¹(F) = y = 1/2 + 2*x

G = (s + 2)/(2*s^2)
G = s/(2*s^2) + 2/(2*s^2)
G = 1/(2*s) + 1/(s^2)
L⁻¹(G) = z = 1/2 + x

y = 1/2 + 2*x
z = 1/2 + x

This concludes our section for Differential Equations. Hope this is helpful and thanks as always! Eddie

Update: There will be more of the Differential Equations series! Look for additional posts during September 2013. Eddie - 8/30/13

This blog is property of Edward Shore. 2013



Differential Equations #6: Laplace Transforms and Solving Differential Equations

In the last post, Differential Equations #5: An intro to Laplace Transforms, we introduced the concept of taking Laplace transforms and inverse Laplace transforms.

Two Laplace transforms we need to take note of:


L( f'(t) ) = s * F(s) - f(0)
L( f"(t) ) = s^2 * F(s) - s * f(0) - f'(0)


The presence of f(0) and f'(0) indicates that can use appropriate conditions to solve the differential equation.

To solve the differential equation using Laplace transformation:

1. Perform a Laplace transform on each term. Remember that
L(y(x)) = F(s)
L(y'(x)) = s*F(s) - y(0)
L(y"(x)) = s^2*F(s) - s*y(0) - y'(0)

2. Solve for F(s). If necessary, use algebraic manipulation to get F(s) in a working form.

3. Find the inverse Laplace transform for F(s). The final solution is:
y(x) = L⁻¹(F(s))


As a reference:
L( f(t) ) → F(s)
1 → 1/s
t^n → n!/(s^(n+1))
e^(a*t) → 1/(s-a)
sin(a*t) → a/(s^2 + a^2)
t*sin(a*t) → (2*a*s)/((s^2 + a^2)^2)
cos(a*t) → s/(s^2 + a^2)
t*cos(a*t) → (s^2 - a^2)/((s^2 + a^2)^2)
sinh(a*t) → a/(s^2-a^2)
cosh(a*t) → s/(s^2-a^2)
e^(a*t)*sin(b*t) → b/((s-a)^2 + b^2)
e^(a*t)*cos(b*t) → (s-a)/((s-a)^2 + b^2)
e^(a*t)*sinh(b*t) → b/((s-a)^2 - b^2)
e^(a*t)*cosh(b*t) → (s-a)/((s-a)^2 - b^2)


Examples:

In our examples, I am going to shorten F(s) to F.

1. y' + 2*y = e^x, y(0) = 3

L(y') = s*F - y(0) = s*F - 3
L(2*y) = 2*F
L(e^x) = 1/(s-1)

Then:
s*F - 3 + 2*F = 1/(s-1)

Solving for F yields:
F = 1/((s-1)*(s+3)) + 3/(s+3)
= (3*s - 2)/((s-1)*(s+3))
= (1/3)/(s-1) + (8/3)/(s+3) (by partial decomposition of fractions)

Then y = L⁻¹(F)
= L⁻¹(1/3)/(s-1) + (8/3)/(s+3))
= 1/3*L⁻¹(1/(s-1)) + 8/3*L⁻¹(1/(s+3))
= 1/3 * e^-x + 8/3 * e^(2*x)

Final answer y(x) = 1/3 * e^-x + 8/3 * e^(2*x)

2. y" - y' = e^x, y(0)=1, y'(0) = 0

L(y") = s^2*F - s*y(0) - y'(0) = s^2*F - s
L(-y) = -L(y) = -(s*F - y(0)) = -s*F + 1
L(e^x) = 1/(s-1)

Then:
s^2*F - s - s*F + 1 = 1/(s-1)
F*(s^2 - s) = 1/(s-1) + s - 1
F = 1/((s-1)*(s^2 - s) + (s-1)/(s^2 - s)
F = 1/(s^3 - 2*s^2 + s) + (s-1)/(s^3 - 2*s^2 + s)

Since s^3 - 2*s^2 + s = s * (s^2 - 2*s + 1) = s * (s - 1)^2,

F = 1/(s * (s-1)^2) + 1/s
F = (1 + s^2 - 2*s + 1)/(s * (s-1)^2)
F = (s^2 - 2*s + 2)/(s * (s-1)^2)

By partial decomposition of fractions:
F = 2/s - 1/(s-1) + 1/(s-1)^2

By inverse Laplace transform:
L⁻¹(F) = y = 2 - e^x + x*e^x

3. y' + y = sin x, y(0) = π/2

L(y') = s*F - π/2
L(y) = s*F
L(sin x) = 1/(s^2 + 1)

(s*F - π/2) + F = 1/(s^2 + 1)
(s + 1) * F = 1/(s^2 + 1) + π/2
F = 1/((s^2 + 1)*(s + 1)) + π/(2*(s+1))

Simplification and partial decomposition of fractions:
F = 1/2 * 1/(s+1) - 1/2 * (s-1)/(s^2 +1) + π/2 * 1/(s+1)
F = (1/2 + π/2) * 1/(s+1) - 1/2 * 1/(s^2 + 1) + 1/2 * 1/(s^2 + 1)

L⁻¹(F) =
(1/2 + π/2)*e^-x - 1/2 * cos x + 1/2 * sin x

4. y' + 2*y = x^2

L(y') = s*F - 2
L(2*y) = 2*F
L(x^2) = 2/s^3

s*F - 2 + 2*F = 2/s^3
(s + 2) * F = 2/s^3 + 2
F = (2 + 2*s^3)/(s^3 * (s + 2))
F = 1/s^3 - 1/2 * 1/s^2 + 1/4 * 1/s + 7/4 * 1/(s+2)

y = 1/2 * x^2 - 1/2 * x + 1/4 + 7/4 * e^(-2*x)

In our next blog, we will look at how Laplace transforms will assist us in solving systems of differential equations.

Thanks as always, comments and questions are welcomed!


This blog is property of Edward Shore. 2013

Differential Equations #5: An intro to Laplace Transforms

Laplace transforms is an integral transform that assists is in solving problems in physics, engineering, and differential equations. This section will introduce Laplace transforms, and we will see how they help in solving some differential equations in the next two sections.

The formal definition of the Laplace transform is:


L( f(t) ) = F(s) = ∫ (e^(-s*t) * f(t) dt, 0, infinity)

(The "L" is usually written in curve like style)

t and s are placeholder variables. Alternatively, we see x in place of t.

L( f(x) ) = F(s) = ∫ (e^(-s*x) * f(x) dx, 0, infinity)

There are many properties of Laplace transforms, but the ones that will help us are:
(1) L( f(t) + g(t) ) = L( f(t) ) + L( g(t) )
(2) L( a*f(t) ) = a*L( f(t) )


Here is a basic table of Laplace Transforms. You can find more complete tables in math reference books and online. One such source is this table from Lamar University in Texas:
(Web page: http://tutorial.math.lamar.edu/pdf/Laplace_Table.pdf )



L( f(t) ) → F(s)
1 → 1/s
t^n → n!/(s^(n+1))
e^(a*t) → 1/(s-a)
sin(a*t) → a/(s^2 + a^2)
t*sin(a*t) → (2*a*s)/((s^2 + a^2)^2)
cos(a*t) → s/(s^2 + a^2)
t*cos(a*t) → (s^2 - a^2)/((s^2 + a^2)^2)
sinh(a*t) → a/(s^2-a^2)
cosh(a*t) → s/(s^2-a^2)
e^(a*t)*sin(b*t) → b/((s-a)^2 + b^2)
e^(a*t)*cos(b*t) → (s-a)/((s-a)^2 + b^2)
e^(a*t)*sinh(b*t) → b/((s-a)^2 - b^2)
e^(a*t)*cosh(b*t) → (s-a)/((s-a)^2 - b^2)


Laplace Transform Examples

1. f(t) = e^(2*t)

From e^(a*t) → 1/(s-a) , a = 2, and then:

L(e^(2*t)) = 1/(s-2)

2. f(t) = cos(3*t)

From cos(a*t) → s/(s^2 + a^2), we find that a = 3 and...

L(cos(3*t)) = s/(s^2 + 9)

3. f(x) = 2 + 3*x

Note that:
1 → 1/s
t^n → n!/(s^(n+1))

L(f(x)) = L(2 + 3*x) = L(2) + L(3*x) = 2/s + 3/s^2

4. f(x) = e^-x * sinh(2*x)

The transform to be used here is: e^(a*t)*sinh(b*t) → b/((s-a)^2 - b^2)
And here a=-1 and b = 2

L(e^-x * sinh(2*x)) = 2/((s+1)^2 - 4)

Which can also be written 2/(s^2 + 2*s - 3)

Inverse Laplace Transforms

L⁻¹( F(s) ) = f(t)

Often taking the inverse is more difficult. Sometimes algebraic manipulation is required to get F(s) into proper form for the inverse transformation. Practice, patience, and perhaps either a calculator with CAS capabilities or mathematical software are all useful tools for taking inverse Laplace transforms.

Let's start with a simple inverse transform.

5. 1/s^2

From t^n → n!/(s^(n+1)), we see that n+1=2, n=1, and...

L⁻¹(1/s^2) = t (or x)

6. 12/(3*s + 9)

The first thing we need to do is algebraically manipulate F(s) into a useable form. Observe that:

12/(3*s + 9) = 4/(s + 3)

Using the transformation e^(a*t) → 1/(s-a), we note that a=-3 and,

L⁻¹(12/(3*s + 9)) = L⁻¹(4/(s + 3)) = 4 * L⁻¹(1/(s + 3))
= 4*e^(-3*t)

7. (2s - 6)/(s^2 + 2*s - 3)

Note: s^2 + 2*s - 3 = (s - 1)*(s + 3)

By decomposition of fractions:
(2s - 6)/(s^2 + 2*s - 3) = -1/(s - 1) + 3/(s + 3)

Then:
L⁻¹(-1/(s - 1) + 3/(s + 3))
= L⁻¹(-1/(s - 1)) + 3 * L⁻¹(1/(s + 3))
= -e^-t + 3*e^(-3*t)

8. (s + 3)/(s^2 + 2*s + 5)

Note that: s^2 + 2*s + 1 = (s + 1)^2

By completing the square in the denominator:
s^2 + 2*s + 5 = s^2 + 2*s + 1 + 4 = (s + 1)^2 + 4

And (s + 3)/(s^2 + 2*s + 5) = (s + 3)/( (s + 1)^2 + 4 )

It looks like the forms we will use are:
e^(a*t)*sin(b*t) → b/((s-a)^2 + b^2)
e^(a*t)*cos(b*t) → (s-a)/((s-a)^2 + b^2)

We will have get the numerator ready: s + 3 = (s + 1) + 2

So we have (s + 3)/( (s + 1)^2 + 4 ) = (s+1)/((s+1)^2+4) + 3/((s+1)^2+4)

Hence:
L⁻¹( (s + 3)/(s^2 + 2*s + 5) )
= L⁻¹( (s+1)/((s+1)^2+4) + 3/((s+1)^2+4) )
= L⁻¹( (s+1)/((s+1)^2+4) ) + L⁻¹( 3/((s+1)^2+4) )
= e^(-t) * cos(2*t) + e^(-t) * sin(2*t)


Now that we had an introduction to Laplace transforms, we will use them to help solve differential equations. Until next time, Eddie!


This blog is property of Edward Shore. 2013

TI-84 Evo BASIC: Hydraulic Radius and Chezy-Manning (Circular Pipes)

TI-84 Evo BASIC: Hydraulic Radius and Chezy-Manning (Circular Pipes) Introduction The program, HYDRAD makes three calculations...