You are on page 1of 6

9/13/13

MATLAB TUTORIAL - by T. Nguyen

| Simulink | | C ontrol Sys tems A pplic ations | | Symbolic C alc ulation | | Side N otes | | A bout this s ite |

1. Laplace Transform Laplace transform of a function f(t) is defined as

where

Laplace transform of a function f(t) can be obtained with Matlab's function laplace. Syntax: L =laplace(f) The usage is demonstrated in the following examples. Example 1. Find the Laplace transform of

Matlab performs Laplace transform symbolically. Thus, you need to first define the variable t as a "symbol". >> syms t Next, enter the function f(t): >> f=5*exp(-2*t); Finally, enter the following command: >> L=laplace(f) Matlab yields the following answer: L= 5/(s+2) You may want to carry out the transformation by hand (or using Laplace transform table) to verify this result. Example 2. Find the Laplace transform of:

edu.levitas.net/Tutorials/Matlab/controlsys.html

1/6

9/13/13

MATLAB TUTORIAL - by T. Nguyen

In Matlab Command Window: >> laplace(12*diff(sym('y(t)'),2)) Note that the function y(t) is defined as symbol with the imbeded command " sym". The number 2 means we wish to take the second derivative of the function y(t). Matlab result: ans = 12*s*(s*laplace(y(t),t,s)-y(0))-12*D(y)(0) where y(0) is the initial condition. Example 3. Find the inverse Laplace transform of

In Matlab Command window: >> ilaplace(1/s-2/(s+4)+1/(s+5)) Matlab result: ans = 1-2*exp(-4*t)+exp(-5*t) or

which is the solution of the differential equation

As an exercise, you should carryout the Laplace transform of the above differential equation with initial condition y(0) = 0 to arrive to the expression of Y(s) as shown above.

2. State-Space As defined in class, the state of a system is a set of variables such that the knowledge of these variables and the input functions will, with the equations describing the dynamics, provide the future state and output of the system. The state of the system is described by the set of the first-order differential equations written in terms of state variables (x1, x2, x3, ..., xn). These first-order differential equations can be written in a general form that can be represented in matrix notation:

where u is a vector of the inputs, x is the element state vector, and y is a vector
edu.levitas.net/Tutorials/Matlab/controlsys.html 2/6

9/13/13

MATLAB TUTORIAL - by T. Nguyen

containing outputs. Example 4. Consider an RLC series circuit as shown in the figure below:

Using Kirchhoff's voltage law, we obtain a differential equation that can be reduced to a set of first-order system:

in matrix form:

Assuming we can measure Vc, then the output relationship can be described by

We will analyze this problem with a step input. In MATLAB you can create an "M-file" including the model parameters. To create an M-file, go to FILE menu and select NEW > M-file. An editor window will pop up. Enter the 12 lines as shown below.

edu.levitas.net/Tutorials/Matlab/controlsys.html

3/6

9/13/13

MATLAB TUTORIAL - by T. Nguyen

Save the file to directory where you can specify the path from the MATLAB command window. Once saved, this M-file can be loaded (executed) by simply go to the appropriate directory and call the M-file by its name. For example, if the above M-file was saved as "rlc.m" ( the extension .m is appended by MATLAB automatically), in MATLAB, simply enter " rlc" at the command prompt to execute the program and enter the requested value accordingly. NOTE: Make sure not to save your M-file with a name that is the same as a Matlab reserved word or function name. The out put of the step response is shown below:

Grids can be shown on the plot with the "grid" command either in your M-file script or at the command line.

3. Converting State-Space to Transfer Function. You may find it useful to obtain a transfer function of the system from the stateedu.levitas.net/Tutorials/Matlab/controlsys.html 4/6

9/13/13

MATLAB TUTORIAL - by T. Nguyen

space representation. This can be achieved by using the MATLAB's function "ss2tf". In the example above, the matrices A, B, C, D were computed according to the userdefined parameters. We will use the computed values from Example 4 above to demonstrate the use of the "ss2tf" command. A screenshot of the conversion with the computed values of A, B, C, and D matrices are shown below

> M E N U >

Vector DEN contains the coefficients of the denominator in descending powers of s. The numerator coefficients are returned in matrix NUM with as many rows as there are outputs y. Thus the above answer from MATLAB can be written as:

___________________________________________________________________________________________________________ T. Nguye n MMIII, MMIV, MMV. All rights re se rve d. R e publication or re distribution of the conte nt in this site , including by fram ing or sim ilar m e ans, is e x pre ssly prohibite d without the prior writte n conse nt of the author.
edu.levitas.net/Tutorials/Matlab/controlsys.html 5/6

9/13/13

MATLAB TUTORIAL - by T. Nguyen

edu.levitas.net/Tutorials/Matlab/controlsys.html

6/6

You might also like