Solving ODEs With the Laplace Transform in Matlab

Preview:

DESCRIPTION

Solve Ode's With Laplace Transforms

Citation preview

  • 3/23/2015 SolvingODEswiththeLaplacetransforminMatlab

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

    SolvingODEswiththeLaplaceTransforminMatlabThisapproachworksonlyfor

    lineardifferentialequationswithconstantcoefficientsrighthandsidefunctionswhicharesumsandproductsof

    polynomialsexponentialfunctionssineandcosinefunctionsHeaviside(step)functionsDirac(impulse)``functions''

    initialconditionsgivenatt=0

    Themainadvantageisthatwecanhandlerighthandsidefunctionswhicharepiecewisedefined,andwhichcontainDiracimpulse``functions''.

    Youmustfirstsavethefilemyplot.minyourdirectory.Unfortunately,theezplotfunctionisbuggyinsomeversionsofMatlab.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

  • 3/23/2015 SolvingODEswiththeLaplacetransforminMatlab

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

    Considertheinitialvalueproblem

    y''+3y'+2y=f(t),y(0)=2,y'(0)=3

    withtherighthandsidefunction

    f(t)=1fort

  • 3/23/2015 SolvingODEswiththeLaplacetransforminMatlab

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

    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

  • 3/23/2015 SolvingODEswiththeLaplacetransforminMatlab

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

    SettheLaplacetransformofthelefthandsideminustherighthandsidetozeroandsolveforY:

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

    FindtheinverseLaplacetransformofthesolution:

    sol=ilaplace(Sol,s,t)

    Plotthesolution:(usemyplotifezplotdoesnotwork)

    ezplot(sol,[0,10])

Recommended