Sie sind auf Seite 1von 4

Math 246 Guide and Project 3 Due Tuesday May 12, 2015

What to Submit:
This project involves both Matlab code and questions about the results. For this project you will need to
create an m-file which does all the tasks listed in this project in order. You should then publish the m-file
and answer the related questions directly on the printout. You will need to use Matlab version 2012a or later
since the symbolic definitions of functions used here will not work on earlier versions.

1 Laplace Transforms and Inverse Laplace Transforms


Matlab can calculate Laplace Transforms easily using the laplace command, as long as you understand exactly
what to plug in. Basically we have to give it the function and both the “input” and “output” variables. We
usually go from t to s and so we’d do something like this:
>> clear all
>> syms s t
>> laplace(exp(3*t),t,s)
ans =
1/(s-3)
So if something it not in our table it’s still easy. Here I wrapped the answer in simplify because it made the
result nicer:
>> simplify(laplace(t^3*sin(t)*exp(3*t),t,s))
ans =
(24*(s^3 - 9*s^2 + 26*s - 24))/(s^2 - 6*s + 10)^4
Task 1: Find and simplify L{t3 sin(2t)}.
Task 2: Find and simplify L{(2t2 − t) cos(5t)}.
Matlab can also take inverse Laplace Transforms with the ilaplace command. For example suppose n o you
know that L{y} = ss+1
2 +9 and you wish to know y. Notationally you could think of this as y = L −1 s+1
s2 +9 and
Matlab can compute this with:
>> clear all
>> syms s t
>> ilaplace((s+1)/(s^2+9),s,t)
ans =
cos(3*t) + sin(3*t)/3
1
Task 3: Find the function y which satisfies L{y} = (s−2)3 .
s2 +s+1
Task 4: Find the function y which satisfies L{y} = s3 −5s2 −2s .
2 Partial Fraction Decompositions
Matlab is not all that it seems. There is an additional symbolic engine called MuPad lurking in the background.
I have no idea why this aspect of Matlab works this way and why it’s not directly integrated into regular Matlab.
Actually the truth is that Matlab bought out MuPad, stuck it in the background and hasn’t done a good job
of integrating it. In any case it allows for some abilities which are not directly accessible from Matlab. One of
those abilities is providing partial fraction decompositions. Rather than go too far into depth about MuPad
let’s just leap to an example:
>> clear all
>> syms s
>> evalin(symengine,’partfrac( (s+3)/(s^2-s-2) )’)
ans =
5/(3*(s - 2)) - 2/(3*(s + 1))
There is also a Matlab command pretty can make the output prettier:
>> clear all
>> syms s
>> pretty(evalin(symengine,’partfrac( (s+3)/(s^2-s-2) )’))
5 2
--------- - ---------
3 (s - 2) 3 (s + 1)
2 2−s
Task 5: Find and make pretty the partial fractions decomposition of s+3 + s3 −s2 −2s .
Task 6: On separate paper (or on your Matlab printout if there’s reasonable room) solve the initial value
problem
y ′′ + 4y ′ + 20y = te2t with y(0) = 1, y ′ (0) = −1
However: You may use laplace, ilaplace and partfrac to skip over tables and calculations. In those cases
simply write a few words indicating which Matlab command you used at that step and how it made your life
easier.
3 Matrices, Vectors, Eigenstuff
We’ve seen how to take determinants of matrices. Let’s just see how we can store them, multiply them and
find the eigenvalues of them. First, here are a couple of matrices:
>> A = [1 2 3;-1 0 2;0 3 1]
A =
1 2 3
-1 0 2
0 3 1
>> B = [1 0 1;2 1 3;1 0 -1]
B =
1 0 1
2 1 3
1 0 -1
Here we multiply them:
>> A*B
ans =
8 2 4
1 0 -3
7 3 8
For finding eigenvalues and eigenvectors it can be nicer to declare the matrix as symbolic. Matlab treats it
a bit differently and will often return nicer answers. All we do is wrap the matrix in sym. Here we find the
eigenvalues and eigenvectors of a 2 × 2 matrix:
>> C = sym([3 -1;4 -2])
C =
[ 3, -1]
[ 4, -2]
>> [evect,eval] = eig(C)
evect =
[ 1/4, 1]
[ 1, 1]
eval =
[ -1, 0]
[ 0, 2]
This is a bit confusing at first. The first part, evect, contains the eigenvectors as columns. The secondpart,

1/4
eval contains the corresponding eigenvectors as entries in a diagonal matrix. So λ = −1 corresponds to
  1
1
and λ = 2 corresponds to .
1
Task 7: Find the eigenvectors and eigenvalues of the matrix
 
2 −5
1 −2

Task 8: Find the eigenvectors and eigenvalues of the matrix


 
−1 −1 0
 5 −3 0
0 0 2
4 Solving Systems of Differential Equations
To close we’ll just cut to the chase. Our dsolve command can solve systems of differential equations. For
example if x(t) and y(t) satisfy the system:

x′ = 2x + y
y ′ = x + 2y

then we can solve this in Matlab with:


>> syms x(t) y(t)
>> [xsoln,ysoln] = dsolve(diff(x) == 2*x+y, diff(y) == x+2*y)
xsoln =
C3*exp(3*t) - C4*exp(t)
ysoln =
C4*exp(t) + C3*exp(3*t)
Task 9: Solve the system of differential equations:

x′ = 3x − y
y ′ = 4x − 2y

and an initial value problem with:


>> [xsoln,ysoln] = dsolve(diff(x) == 2*x+y, diff(y) == x+2*y,x(0)==1,y(0)==-2)
xsoln =
(3*exp(t))/2 - exp(3*t)/2
ysoln =
- exp(3*t)/2 - (3*exp(t))/2
Task 10: Solve the previous problem’s differential equation along with x(0) = 2 and y(0) = −3.
As a closing note this differential equation (not the IVP) in matrix form is
   
′ x(t) 2 1
X = AX where X = X(t) = and A =
y(t) 1 2

We can also put this in Matlab:


>> clear all
>> syms x(t) y(t)
>> X=[x;y];
>> A = [2 1;1 2];
>> [xsoln,ysoln] = dsolve(diff(X) == A*X)
xsoln =
C1*exp(3*t) - C2*exp(t)
ysoln =
C2*exp(t) + C1*exp(3*t)