Laplace Transforms using MATLAB ME 344 This document describes a number of useful MATLAB commands for dealing with Laplace transforms. Several basic MATLAB commands are covered: roots deconv residue find the roots of a polynomial polynomial division find the coefficients for a partial fraction expansion As well as two from Symbolic Math Toolbox: laplace ilaplace take the Laplace transform take the inverse Laplace transform The Symbolic Math Toolbox is an optional add-on to MATLAB that is normally purchased separately; the MATLAB installation in the public computer labs in Pangborn includes this toolbox. Roots of a polynomial The roots of a polynomial can be found using the aptly named ROOTS command. You give MATLAB a vector containing the coefficients of the polynomial in descending order of powers of the variable. For example, if the polynomial is s 3 + 3s 2 + 2s + 5, then you would represent that as the vector [1 3 2 5] in MATLAB. Be careful to include any coefficients that are zero, for example, s 3 + 5 would be represented by [1 0 0 5] since the s 2 and s terms don’t exist if you just entered [1 5] that would mean s + 5, not s 3 + 5. Here’s an example of use of the ROOTS command, and how to intrepret the answer: A=[1 8 19 12]; roots(A) takes the roots of the polynomial s 3 + 8s 2 +19s +12 MATLAB responds with the answer -4.0000 -3.0000 -1.0000 which means that the roots of the polynomial are s = -4, s = -3, and s = -1. In other words, you could factor the polynomial s 3 + 8s 2 +19s +12 into ( s + 4)( s + 3)( s +1). Polynomial Division Division of one polynomial by another can be accomplished using the command DECONV (short for deconvolution), which requires two input vectors: the first represents the numerator and the second the denominator (using the same representation as the ROOTS command). DECONV returns two output vectors representing polynomials: the first is the quotient and the second is the remainder. The quotient stands alone but the remainder must be placed over the original denominator. Thus, the syntax is [Q,R]=deconv(B,A) and the answer should be interpreted to mean that the fraction B R =Q+ . A A In problems where one polynomial divides evenly into another, the remainder will be simply a vector of zeros... however, most ratios of polynomials don’t divide evenly. You can think of it as similar to dividing 7 1 7 by 2. The answer is 3 with a remainder 1, so you’d write = 3+ . 2 2 For example, to resolve the fraction f (x) = 3x 3 - 2x 2 + 4 x - 3 you’d type x 2 + 3x + 3 A=[1 3 3]; B=[3 -2 4 -3]; [Q,R]=deconv(B,A) to which MATLAB responds Q = R = 3 0 which means that f (x) = (3x -11) + -11 0 28 30 28x + 30 . x 2 + 3x + 3 Partial Fraction Expansion The command RESIDUE can be used to perform partial fraction expansion directly (RESIDUE itself makes use of both ROOTS and DECONV behind the scenes). You provide two input vectors, which again represent the numerator and denominator polynomials, just like the DECONV command. MATLAB returns three outputs: the first is a vector of residues, the second a vector of poles, and the third a vector of coefficients for any remainder polynomial that exists. Here’s an example to show you how it works: if F(s) = A=[1 3 2 0]; B=[3 1]; [R,P,K]=residue(B,A) B(s) 3s +1 then you’d type = A(s) s 3 + 3s 2 + 2s and MATLAB responds with R = -2.5000 2.0000 0.5000 P = -2 -1 0 K = [] The poles P are the roots of the denominator, the same as you’d get with roots([1 3 2 0]). The partial fraction expansion includes one term for each of them, for which the denominator is s minus the pole. The residues are placed in corresponding order as the numerators of each of these terms, like this: F(s) = -2.5 2 0.5 + + s + 2 s +1 s You would then be able to perform the inverse Laplace transform on each term of the expansion, which, for this example, would give f (t) = -2.5e-2t + 2e-t + 0.5 for t > 0. In this example the K vector is empty because the denominator polynomial A(s) had higher order than the numerator polynomial B(s), so there is no remainder. If K wasn’t empty, you’d interpret the numbers in K as coefficients of a polynomial (without any denominator) that would be added to the end of the partial fraction expansion. For example, if R, P, and K all had three elements, you’d write F(s) = R(1) R(2) R(3) + + + K(1)s 2 + K(2)s + K(3) s - P(1) s - P(2) s - P(3) Special Cases: Repeated roots - If the poles vector P ever contains repeated elements, then you must do the same thing as if you were performing P.F.E. by hand: the residue corresponding to the second instance of a repeated pole p gets placed above (s-p)2, the third (if its repeated more than twice) goes above (s-p)3, and so on. Complex/imaginary roots - MATLAB will factor quadratics with complex or imaginary roots, rather than leaving them as a quadratic. When you have complex (or imaginary) poles, the resulting inverse Laplace transform will give exponentials with complex or imaginary arguments, which are mathematically equivalent to the sines and cosines you’d get if you didn’t factor the quadratic. Laplace Transforms with MATLAB’s Symbolic Math Toolbox To use commands from the Symbolic Math Toolbox, you first need to create symbolic objects for your variables (s and t would be the logical choices). The SYMS command is a shortcut for constructing symbolic objects; you can also use the longer SYM command. syms s t To take the Laplace transform of is equivalent to s=sym(‘s’) t=sym(‘t’) f (t) = te-3t type laplace(t*exp(-3*t)) and MATLAB responds with 1/(s+3)^2 To take the inverse Laplace transform of F(s) = you’d type B(s) 3s +1 = 3 A(s) s + 3s 2 + 2s ilaplace((3*s+1)/(s^3+3*s^2+2*s)) and MATLAB responds with answer -5/2*exp(-2*t)+2*exp(-t)+1/2 If the version of MATLAB you are using doesn’t recognize these commands, the Symbolic Math Toolbox may not be present.