9. Laplace Transform
Home Up Quick Reference M-files Laser Printing 1. Matlab Basics 2. Sequences & Series 3. Taylor Series 4. Fields & Flows 5. ODE Models 6. Symbolic ODE 7. Systems & 2nd order 8. Numerical ODE 9. Laplace Transform

[Objectives | Exercise | Example A | Example B  ]

OBJECTIVES
Use Matlab's Symbolic Toolbox package to solve a differential equation via Laplace transforms. 

EXERCISE

1) Use Matlab to compute the Laplace transform of the following functions

cos(3t),     exp(2t)sin(t),   and   t^7.

Then use Matlab to compute the inverse Laplace transform of the three results you just found, see Example A

 2)  Using Laplace Transforms, solve the following initial value problem (see Example B  below):

y'' - 4y' - 5y = cosh(2t),       y(0)=1,        y'(0)=4 

Example A: 

The following commands compute the Laplace transform of  t^3*sin(2*t):

>> syms s t
>> Y=laplace(t^3*sin(2*t),t,s)

The result is:

   
      Y = 96/(s^2+4)^4*s^3-48/(s^2+4)^3*s.

You may make the answer look better by typing      >>  pretty(Y) .

To undo the Laplace transform, simply use the command:

>> y=ilaplace(Y,s,t)

The result is

            y =t^3*sin(2*t)

which is the original function, as it should be. 

Example B:

Find a solution to the following differential equation with initial conditions 


y''+2y'+y=sin(2t),    y(0)=-2,       y'(0)=3.         (**)

The first step is to define the symbolic variables we will need and then enter our differential equation. 

>>syms s t Y
>>ode='D(D(y))(t)+2*D(y)(t)+y(t)=sin(2*t)'

The notation we used above in writing our ode is a little different than what we have used before. In general, y(t) refers to y, D(y)(t) refers to the first derivative of y, D(D(y))(t) refers to the second derivative of y, and so on. Next, we apply the Laplace transform to both sides of our equation. 

>>ltode=laplace(ode,t,s)

The result is:

ltode =

s*(s*laplace(y(t),t,s)-y(0))-D(y)(0)+2*s*laplace(y(t),t,s)-2*y(0)+laplace(y(t),t,s) = 2/(s^2+4)

The result gives an algebraic expression for the unknown function laplace(y(t),t,s). To simplify this expression, we will replace laplace(y(t),t,s) by Y and also plug in our initial conditions. This is done using the "subs'' command as follows: 

>>eqn=subs(ltode,{'laplace(y(t),t,s)','y(0)','D(y)(0)'},{Y,-2,3})

This command substitutes  laplace(y(t),t,s) by Y, y(0) by -2, and Dy(0) by 3 in Itode  and gives:

        eqn =s*(s*Y+2)+1+2*s*Y+Y = 2/(s^2+4)

We may solve this equation for Y using the command:

>>Y=solve(eqn,Y)

The result is

            Y =-(2*s^3+8*s+2+s^2)/(s^2+4)/(2*s+1+s^2)

which is the Laplace transform of the function y solving Eq. (**).

We now find y(t) by inverting the Laplace transform:

>>y=ilaplace(Y,s,t)

            y = 7/5*t*exp(-t)-46/25*exp(-t)-4/25*cos(2*t)-3/25*sin(2*t)

which is the solution to (**) as can be verified using MATLAB:

>>diff(y,2)+2*diff(y,1)+y

            ans = sin(2*t) 

and we may check the initial conditions using:

t=0; y_0=eval(y), Dy_0=eval(diff(y))

which gives

            y_0 = -2    and  Dy_0 = 3.

Just as it should be! 

[Objectives | Exercises | Example ]

 

Jump to Bruce Driver's Homepage.                       Jump to Current Courses Page.

Last modified on November 19, 1999 at 11:57 AM.