4
Solving ODEs with the Laplace Transform in Matlab This approach works only for linear differential equations with constant coefficients righthand side functions which are sums and products of polynomials exponential functions sine and cosine functions Heaviside (step) functions Dirac (impulse) ``functions'' initial conditions given at t =0 The main advantage is that we can handle righthand side functions which are piecewise defined, and which contain Dirac impulse ``functions''. You must first save the file myplot.m in your directory. Unfortunately, the ezplot function is buggy in some versions of Matlab. If ezplot does not work, try to use myplot instead. Simple example Consider the initial value problem y'' + 3 y'+2 y = e t , y(0) = 4 , y'(0) = 5 Define the necessary symbolic variables: syms s t Y Define the righthand side function and find its Laplace transform: f = exp(‐t) F = laplace(f,t,s) Find the Laplace transform of y'(t): Y 1 = sY y(0) Y1 = s*Y ‐ 4 Find the Laplace transform of y''(t): Y 2 = sY 1 y'(0) Y2 = s*Y1 ‐ 5 Set the Laplace transform of the left hand side minus the right hand side to zero and solve for Y: Sol = solve(Y2 + 3*Y1 + 2*Y ‐ F, Y) Find the inverse Laplace transform of the solution: sol = ilaplace(Sol,s,t) Example with piecewise defined righthand side function

Solving ODEs With the Laplace Transform in Matlab

Embed Size (px)

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])