0% found this document useful (0 votes)
9 views5 pages

ECE460L Lab1 Guide

Uploaded by

Fetty Mike
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

ECE460L Lab1 Guide

Uploaded by

Fetty Mike
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Lab 1 Guide: MATLAB Basics, Symbolic Math Toolbox, and Laplace

Transforms
ECE460L
Duncan Tyree

Objective
The objectives of this lab are to review basic MATLAB functions and syntax, introduce the
Symbolic Math Toolbox, and apply these concepts to find the Laplace transforms and Inverse
Laplace transforms of various example functions. As a review, we go through the content of the
first three chapters of “Introduction to MATLAB for Engineering Students” by David Houcque.
A short tutorial introducing the Symbolic Math Toolbox will be provided, including how to
declare symbols and equations, as well as how to find the solutions, integrals, and derivatives of
different functions. Finally, we will move on to the main content of the lab, which will focus on
applying these skills to find the Laplace, inverse Laplace transforms, and partial fraction of an
example problem.

Required Software
- MATLAB installation with Symbolic Math Toolbox

Procedure
The following procedures will provide instructions on how to ensure the Symbolic Math Toolbox
is installed, review basic MATLAB syntax and functions, utilize the Symbolic Math Toolbox,
and apply these methods to Laplace transforms and inverse Laplace transforms.
Symbolic Math Toolbox installation
1. Open MATLAB and go to the “Home” tab at the top of the screen.
2. Click on the “Add-Ons” button. This will open a new window where all the MATLAB
packages can be found.
3. Search for “Symbolic Math Toolbox” in the search bar and click on package.
4. If the package is already installed, a green banner which says “Installed” should be
overlaying the package thumbnail image.
5. If the package is not installed, install the package. This step could take a few minutes to
complete.
Basic Math Operations, Matrices, and Functions in MATLAB
MATLAB can be used as a calculator in the command line. Addition, subtraction, multiplication,
and division are performed using the “+”, “-“, “*”, and “/” operators. MATLAB follows the
normal order of operations. Compute the following:
1. In MATLAB, open a new live script. This will be the expected format for lab reports and
code submissions.
2. 4825 + 682
3. 112406 – 58345
4. 256 * 800
5. 9564 / 248
6. (256 * 800) / 248
Variables and functions can be declared similarly to other coding languages. Declared variables
can then be overwritten and used in calculations just like other coding languages. Table 1 lists
several default functions available in MATLAB.
1. Declare the variable x = 5.
2. Assign a new value of 10 to the variable x.
3. Compute x 2 and √ x using “x^2” and “sqrt(x)”.

Table 1. List of default MATLAB functions.


MATLAB Syntax Function MATLAB Syntax Function
cos(x) Cosine abs(x) Absolute value
sin(x) Sine sign(x) Signum function
tan(x) Tangent max(x) Maximum value
acos(x) Arc cosine min(x) Minimum value
asin(x) Arc sine ceil(x) Round up
atan(x) Arc tangent floor(x) Round down
exp(x) Exponential round(x) Round to nearest int
sqrt(x) Square root rem(x) Remainder from division
operation
log(x) Natural logarithm angle(x) Phase angle
log10(x) Common conj(x) Complex conjugate
logarithm

Vectors and matrices can be defined using brackets. Each row of a matrix is defined by listing
out all of the components in the row separated by spaces. Semicolons are used to differentiate
between each row in the matrix. Type the following into MATLAB to declare a vector V and a
matrix M.
1. V = [0 5 4 8]
2. A = [0; 5; 4; 8]
3. M = [2 8 3 6; 4 8 4 8; 5 9 0 4; 2 9 2 9]
The transpose of a matrix is found using the (‘) operator. Subsets of the vectors and matrices can
be accessed using array slicing. Use the following commands to find different slices of the
previously defined arrays. The (:) operator denotes either all columns or all rows depending on
the context.
1. V(1:3)
2. V(3, end)
3. M(2,1)
4. M(2,:)
5. M(:,2:3)
6. M([2 3], [1 2])
7. M([2 1 3], :)

Symbolic MATLAB Introduction


The Symbolic Math Toolbox is a powerful tool which can be used to perform operations on
functions symbolically. The following procedure is a tutorial of how to declare symbols and
symbolic functions, perform simplifications and substitutions, solve functions given a specific
variable value, and more. Symbols are declared using “syms a b c” and so on. Most Greek letters
can be declared by typing the English spelling.
1. clear all
2. syms a b c theta phi
3. Declare the function a = b*theta + c*phi
4. Declare symbols y and x and the function y=x 2−2

Functions can be added, subtracted, multiplied, and divided using the basic operators.
1. Compute a * y
2. Declare symbols y1 and y2
3. Declare functions y1 = x^2 + 10 and y2 = x^2 – 4
4. Compute y1 * y2, y1 / y2, y1 + y2, and y1 – y2
We can find the zeroes of each of these functions using the “solve” function.
1. Set y1 = 0 using the syntax “y1 == 0” then solve for the zeroes of y1 using “solve(y1)”
2. Solve equation y2 for x using “solve(y2,x)”
3. Declare new syms x1 and d and a new function x1 = d + 5
4. Substitute x1 in for x in equation y2 using “subs(y2, x, x1)”
5. Solve y2 for d using the solve command
Integrals and derivatives can be found by using the “int()”, “diff()”, and “gradient()” commands.
1. Find the integrals of y1 and y2 using “int(y1,x)” and “int(y2,d)”
2. Find the first derivatives of y1 and y2 using “diff(y1)” and “diff(y2)”
The “gradient()” command has a very similar syntax, see the MATLAB documentation for more
information.
Assignment: Laplace Transforms, Inverse Laplace Transforms, and Partial Fraction
Decomposition
Next, the previously explored methods will be applied to find Laplace transforms and inverse
Laplace transforms. Solve the following problems using the Symbolic Math Toolbox. Make use
of the table of common Laplace transforms and inverse Laplace transforms provided in class to
perform substitutions.
Example: Find the Laplace transform of the following function with the given initial conditions.
'' '
y − y −2 y=0 (1)

with
y ( 0 )=1
'
y ( 0 )=0
Recall that the Laplace transform of the second derivative of a function is given by the
following:

L ( y '' ) =s 2 Y ( s )−sy ( 0 ) − y ' ( 0 ) ,

where Y ( s )=L { y ( t ) } is the Laplace transform of a function y (t ). The Laplace transform of the
first derivative is given by

L ( y ' )=sY ( s )− y ( 0 ) ,

and the Laplace transform of 2 y is simply 2 Y (s). Substitute these equations into equation (1) to
get

[ s2 Y ( s )−sy ( 0 )− y ' ( 0 ) ]−[ sY ( s )− y ( 0 ) ]−2Y ( s ) =0. (2)

Plug in the initial conditions and solve for Y (s) to obtain the following polynomial fraction:
s−1 (3)
Y ( s )=. 2
s −s−2
Finally, partial fraction decomposition and inverse Laplace transforms can be used to find the
solution to equation (1).
Use the following procedure to compute this symbolically in MATLAB.
1. Declare syms z, t, Z, s, L1, L2, and L3
2. Declare functions d2z = diff(z,2) and dz = diff(z)
3. Declare an equation “eqn = d2z – dz – 2*z == 0”
4. Declare the Laplace transforms above:
a. L1 = (s^2 * Z) – (s * 1) – 0
b. L2 = (s * Z) – 1
c. L3 = 2 * Z
5. Then you can get the Laplace transform of equation (1) by setting
a. eqn_1 = L1 – L2 – L3 == 0
b. Solve the equation for Z using “eqn_2 = solve(eqn_1,Z)”
6. The partial fraction decomposition can be found by using the “partfrac” command on
eqn_2 (i.e. “partfrac(eqn_2)”)
7. Use the table of Laplace transforms provided in class and the partial fraction
decomposition to find the solution to equation (1). (Hint: the solution will be the sum of
two exponential functions)

Lab Report Guidelines


The lab report will be turned in as a PDF export of the live script worked on in class. Add text to
explain your work in each section using the live editor tool. Requirements of the report are as
follows:
1. Title and collaborator names (if the lab was completed in a group)
2. Lab section (i.e. ECE460L-001, ECE460L-002, or ECE460L-003)
3. Section headers for each of the sections above
a. Lab objectives and summary
b. Basic math operations, matrices, and functions
c. Symbolic MATLAB introduction
d. Laplace transforms, inverse Laplace transforms, and partial fraction
decomposition
e. Conclusion

You might also like