Vous êtes sur la page 1sur 2

Math 282

To use MATLAB to find a Laplace transform, enter the command as laplace(function).


For example, either
>> Y=laplace(exp(2*t) or
>> Y=laplace(exp(2*t),t,s) (to explicitly state the domain variables of f and L(f)
computes the Laplace transform of e2t, gives the answer as a function of s, and calls the result Y.
When you enter either of these, you should get the result Y = 1/(s-2)
To undo this, tell MATLAB to compute the inverse Laplace transform with the command ilaplace
>> y = ilaplace(1/(s-2),s,t) (ilaplace(Y,s,t)) would also work if Y is defined as in the above step)

To solve a differential equation using MATLAB, we start by letting Y represent the Laplace transform of the
desired variable, Y1 the Laplace transform of y, Y2 the Laplace transform of y, and so on.

In this example, I solve the IVP y'+3y=2e-3t, y(0)=5. Comments in italics are not part of the MATLAB code
syms s t Y
F=laplace(2*exp(-3*t),t,s) storing the Laplace of the right-hand side of the equation as F
Y1=s*Y-5 we dont know Y, but we do know the relationship between Y1 and Y
solve(Y1+3*Y-F,Y) The expression prior to the comma is the left side of the differential
equation minus the right side (Matlab always solves expressions for
0, and solving for when the difference of these expressions equals 0 is
equivalent to solving the original equation. It solves for Y as the
variable, remembering that Y1 is defined in terms of Y).
This solves for Y, the laplace transform of the desired answer.
ilaplace(ans,s,t) And now we have the answer!

Note: For some reason, sometimes MATLAB leaves part of the answer in terms of ilaplace rather than
computing the inverse Laplace transform. If this happens, use the simplify command and it will finish solving
for y. You can then proceed to graph or otherwise analyze the solution.

If you have a 2nd order equation, the commands might look something like this:
syms s t Y
F=laplace(2*exp(-3*t),t,s)
Y1=s*Y-5
Y2=s*Y1+1
solve(Y2+3*Y1+2*Y-F,Y)
ilaplace(ans,s,t)
MATLAB project #2.

Your solution must be e-mailed to me prior to class on April 28 (T/R class) or April 29 (MWF class) to receive
credit.

Preliminary: Type the following commands in MATLAB to see what each does:
>> ezplot(heaviside(t),[-2,6])
>> ezplot(heaviside(t-3),[-2,6])
>> ezplot(heaviside(t+1),[-2,6])
Now, try to anticipate what each of the following graphs will look like, and then check your guesses:
a. >> ezplot(heaviside(t-1) - heaviside(t-3),[-2,6])
b. >> ezplot( (t-1)*heaviside(t-1) (t-3)*heaviside(t-3),[-2,6])
c. >> ezplot( t*(heaviside(t-1)-heaviside(t-3)) , [-2,6])

Create a MATLAB diary and record the following work (instruction on creating a diary are included with the
first MATLAB project. You can also find help by typing help diary at the prompt in MATLAB)

1. Use MATLAB to compute the Laplace transform of the following functions (yes, you have done many
of these by hand already, but thats ok. Were just making sure that MATLAB also knows how to get
the right answers!)
a. y= 1
b. y= t+3
c. y=t*sin(t)
0 <3
d. { 3 } (hint: start by re-writing this using the Heaviside function)
3

2. Use MATLAB to solve the IVP: y + 4y = sin(2t), y(0) = 0

3. Use MATLAB to solve the IVP: y + 4y+4y = e-2t, y(0) = 1, y(0)= 3

2<5
Questions 4, 5 and 6 all relate to the differential equation + 2 + 10 = { }
0
4. Express the right hand side of this equation using Heaviside functions.

5. Use MATLAB to solve the differential equation from part (a) with initial conditions y(0) = 0, y(0)= 1

6. Graph the solution curve on the domain 0t8. At the top of the Figure 1 window which contains
your graph, select File then Save as and save the picture with the file name YourLastNameProject2
(so, for example, I would save the graph as PennProject2)

Turn your diary off after answering #6.

Send me an email containing 2 attachments: your diary, and the saved graph from #6.

Vous aimerez peut-être aussi