0% found this document useful (0 votes)
207 views

Solving ODEs With The Laplace Transform in Matlab

This document discusses solving ordinary differential equations (ODEs) with the Laplace transform in Matlab. It can handle linear ODEs with constant coefficients and right-hand sides that are polynomials, exponentials, trigonometric, step, or impulse functions. Three examples are provided to illustrate solving ODEs with piecewise, exponential, and impulse right-hand side functions using the Laplace transform in Matlab.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
207 views

Solving ODEs With The Laplace Transform in Matlab

This document discusses solving ordinary differential equations (ODEs) with the Laplace transform in Matlab. It can handle linear ODEs with constant coefficients and right-hand sides that are polynomials, exponentials, trigonometric, step, or impulse functions. Three examples are provided to illustrate solving ODEs with piecewise, exponential, and impulse right-hand side functions using the Laplace transform in Matlab.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

3/23/2015

SolvingODEswiththeLaplacetransforminMatlab

SolvingODEswiththeLaplaceTransformin
Matlab
Thisapproachworksonlyfor
lineardifferentialequationswithconstantcoefficients
righthandsidefunctionswhicharesumsandproductsof
polynomials
exponentialfunctions
sineandcosinefunctions
Heaviside(step)functions
Dirac(impulse)``functions''
initialconditionsgivenatt=0
Themainadvantageisthatwecanhandlerighthandsidefunctionswhicharepiecewisedefined,and
whichcontainDiracimpulse``functions''.
Youmustfirstsavethefilemyplot.minyourdirectory.Unfortunately,theezplotfunctionisbuggy
insomeversionsofMatlab.Ifezplotdoesnotwork,trytousemyplotinstead.

Simpleexample
Considertheinitialvalueproblem
y''+3y'+2y=et,y(0)=4,y'(0)=5
Definethenecessarysymbolicvariables:
symsstY

DefinetherighthandsidefunctionandfinditsLaplacetransform:
f=exp(t)
F=laplace(f,t,s)

FindtheLaplacetransformofy'(t):Y1=sYy(0)
Y1=s*Y4

FindtheLaplacetransformofy''(t):Y2=sY1y'(0)
Y2=s*Y15

SettheLaplacetransformofthelefthandsideminustherighthandsidetozeroandsolveforY:
Sol=solve(Y2+3*Y1+2*YF,Y)

FindtheinverseLaplacetransformofthesolution:
sol=ilaplace(Sol,s,t)

Examplewithpiecewisedefinedrighthandsidefunction
http://terpconnect.umd.edu/~petersd/246/matlablaplace.html

1/4

3/23/2015

SolvingODEswiththeLaplacetransforminMatlab

Considertheinitialvalueproblem
y''+3y'+2y=f(t),y(0)=2,y'(0)=3
withtherighthandsidefunction
f(t)=1fort<3
f(t)=t2for3<t<6
f(t)=2fort>6
Definethenecessarysymbolicvariables:
symsstY

Astherighthandsidefunctionispiecewisedefined,rewriteitintermsoftheHeavisidefunctionH(t)
(a.k.a.unitstepfunction):
For
f(t)=f1(t)fort<t1
f(t)=f2(t)fort1<t<t2
f(t)=f3(t)fort>t2
wecanwritethefunctionas
f(t)=f1(t)+(f2(t)f1(t))H(tt1)+(f3(t)f2(t))H(tt2)
whereH(t)denotestheHeavisidefunctiondefinedbyH(t)=0fort0andH(t)=1fort>0.
(NotethatH(tc)=uc(t)withuc(t)asdefinedinclassandthetextbook).
ThereforeweuseinMatlab
f=1+((t2)1)*heaviside(t3)+(2(t2))*heaviside(t6)
ezplot(f,[0,10])

FindtheLaplacetransformoftherighthandsidefunctionf(t):
F=laplace(f,t,s)

FindtheLaplacetransformofy'(t):Y1=sYy(0)
Y1=s*Y2
http://terpconnect.umd.edu/~petersd/246/matlablaplace.html

2/4

3/23/2015

SolvingODEswiththeLaplacetransforminMatlab

FindtheLaplacetransformofy''(t):Y2=sY1y'(0)
Y2=s*Y13

SettheLaplacetransformofthelefthandsideminustherighthandsidetozeroandsolveforY:
Sol=solve(Y2+3*Y1+2*YF,Y)

FindtheinverseLaplacetransformofthesolution:
sol=ilaplace(Sol,s,t)

Plotthesolution:(usemyplotifezplotdoesnotwork)
ezplot(sol,[0,10])

ExamplewithDirac``function''
Considertheinitialvalueproblem
y''+2y'+10y=1+5 (t5),y(0)=1,y'(0)=2
Definethenecessarysymbolicvariables:
symsstY

Definetherighthandsidefunction:
f=1+5*dirac(t5)

FindtheLaplacetransformoftherighthandsidefunction:
F=laplace(f,t,s)

FindtheLaplacetransformofy'(t):Y1=sYy(0)
Y1=s*Y1

FindtheLaplacetransformofy''(t):Y2=sY1y'(0)
Y2=s*Y12
http://terpconnect.umd.edu/~petersd/246/matlablaplace.html

3/4

3/23/2015

SolvingODEswiththeLaplacetransforminMatlab

SettheLaplacetransformofthelefthandsideminustherighthandsidetozeroandsolveforY:
Sol=solve(Y2+2*Y1+10*YF,Y)

FindtheinverseLaplacetransformofthesolution:
sol=ilaplace(Sol,s,t)

Plotthesolution:(usemyplotifezplotdoesnotwork)
ezplot(sol,[0,10])

http://terpconnect.umd.edu/~petersd/246/matlablaplace.html

4/4

You might also like