Professional Documents
Culture Documents
Lisa Desai
ECE 3041 L03
Table of Contents
CHAPTER 1
1.1 Introduction 1
1.2 System Requirements 1
1.2.1 Matlab System Requirements 1
1.2.2 Mathcad System Requirements 2
CHAPTER 2
Inverting Systems of Equations Using Mathcad
2.1 Defining Variables 3
2.1.1 How to Define Variables in Mathcad 3
2.1.2 How to add units to variables 4
2.1.3 Defining Resistor (R) Variables 4
2.1.4 Defining Conductance (G) Variables 5
2.1.5 Defining Current (I) variables 5
2.2 Creating Matrices 6
2.3 Displaying Answer 9
CHAPTER 3
Inverting Systems of Equations Using Matlab
3.1 Defining Variables 10
3.1.1 How to Define Variables in Matlab 10
3.1.2 Defining Resistor (R) Variables 11
3.1.3 Defining Conductance (G) Variables 11
3.1.4 Defining Current (I) Variables 12
3.2 Creating Matrices 13
CHAPTER 4
Two-Dimensional Plots using Mathcad
4.1 Defining Variables 14
4.2 Creating Graphs 15
4.3 Adding Labels to Graphs 17
CHAPTER 5
Two-Dimensional Plots using Matlab
5.1 Defining Variables 19
5.2 Creating Graphs 20
5.3 Adding Labels to Graphs 21
CHAPTER 6
Bode Plots using Mathcad
6.1 Defining Variables 23
6.2 Creating Vectors 25
6.3 Creating Bode Plot 26
CHAPTER 7
Bode Plots using Matlab
7.1 Defining Variables 31
7.2 Defining Transfer Functions 32
7.3 Creating Bode Plots 33
7.4 Changing Units 34
CHAPTER 8
Troubleshooting
8.1 Problems with Matrix Multiplication 36
8.2 Problems with Defined Variables 36
8.3 Problems with Units in Mathcad 36
APPENDIX A: Glossary 38
CHAPTER 1
1.1 Introduction
Matlab and Mathcad are software programs that have the capability to perform intensive
mathematical computations faster than traditional methods. As an engineering student it
is important to be familiar with these two programs, as they will be used extensively in
your studies.
Three types of problems are introduced in this instruction guide. They are systems of
equations, two-dimensional plots, and bode plots. These three problems are very
important to an engineering student. By the end of this guide, you will be familiar with
Matlab and Mathcad. You will also be familiar with solving equations and plotting. You
will also notice the differences in solving problems and interfaces of Matlab and
Mathcad.
Matlab and Mathcad both have their advantages but Mathcad has proven to be easier to
use. In chapter 2 and 3 the problem that is solved is systems of equations. In Mathcad
entering a matrix is much easier than Matlab. When entering a matrix in Mathcad, an
actual matrix appears whereas in Matlab you enter it in like a vector with the rows
separated by semicolons. Also Mathcad allows you to enter functions of an undefined
variable that can then be inputted later like in Chapter 4 and 6 when defining voltage and
transfer functions. In Matlab every variable must be defined before being used. Even
variables that vary like time.
• Operating System
o Microsoft Windows XP (SP1 or SP2)
o Microsoft Windows 2000 (SP3 or SP4)
o Microsoft Windows Server 2003
o Microsoft Windows Vista
• Processors
o Intel Pentium (IV or above)
o Intel Celeron
1
o Intel Xeon
o Intel Core
o AMD Athlon
o AMD Opteron
• 500 MB of disk space
• 512 MB of RAM (1024 MB Recommended)
• Operating System
o Microsoft Windows XP Service Pack (SP) 2
o Microsoft Windows Home Edition SP2
• Processor: Pentium/Celeron, 400 MHz or higher
• 550 MB of disk space
• 256 MB of RAM (512 MB recommended)
2
CHAPTER 2
Given the values for G and I, you will be solving for the V values.
G is conductance and is defined as 1/R where R is resistance.
I is current and the unit is amps.
V is voltage and the unit is volts.
3
Figure 1. Evaluation Toolbar.
To insert units, multiply the variable (asterisk) and then click on the icon
for the measuring cup on the top of the command bar as shown in the
figure below.
1. Start Mathcad
2. Left click in whitespace/workbook
3. Define R1 = 20*k. Keyboard sequence for this would be R, period, 1,
colon, 20, asterisk, click on measuring cup on command bar, click on
kilo-ohms
4. Left click below the definition of R1 or hit enter after the previous step.
5. Define the following variables in the same manner as R1
a. R2 = 68* k
b. R3 = 18* k
c. R4 = 33* k
d. R5 = 15* k
e. R6 = 24* k
f. R7 = 43* k
4
Figure 3. All resistor variables defined in Mathcad.
All the G variables defined will look like the following figure
All the I variables defined will look like Figure 5, shown below
5
2.2 Creating Matrices
1. To insert a matrix, go to InsertMatrix
Note: Keyboard
shortcut for
inserting a
matrix is Ctrl+m
6. Enter the following variables so that your matrix looks like the
following
6
Figure 9. Creating the voltage matrix.
10. Add the following variables so that your matrix looks like the
following figure
11. Push the right arrow to move the cursor outside the matrix
12. Raise the matrix to the -1 power by typing ^, -, 1
13. Push the right arrow to move the cursor out of the power
7
14. Type * (asterisk on the keyboard) to multiply
15. Insert a 5 by 1 matrix (Ctrl + m)
16. Type in the following variables so that your matrix looks like the
following
After carrying out the above steps, you should have the following
1
VA G1 + G2 G2 0 0 0 I1
VB G2 G2 + G4 + G5 G5
0 G4
0
VC := 0 G5 G5 + G7 G7 0 I2
V 0 0 G7 G7 + G6 G6
I2
D
VE 0 G4 0 G6 G3 + G4 + G6 0
Figure 15. The complete definition of the voltage matrix.
8
2.3 Displaying the Answer
1. Insert a 5x1 matrix (Ctrl+m)
2. Enter the following
VA
VB
VC
V
D
VE
Figure 16. Entering the voltage matrix.
9
CHAPTER 3
In this section you will learn how to do the example from Chapter 2 in Matlab.
Consider the following system of equations arranged in matrices
Given the values for G and I, you will be solving for the V values.
G is conductance and is defined as 1/R where R is resistance.
I is current and the unit is amps.
V is voltage and the unit is volts.
10
To prevent Matlab
from repeating the
entry back after you
hit enter, place a
semicolon at the end
of the definition.
1. Start Matlab
2. Define R1 = 20. Keyboard sequence would be R,1, equal, 20,
semicolon, enter
3. Define the following variables in the same manner as R1
a. R2 = 68
b. R3 = 18
c. R4 = 33
d. R5 = 15
e. R6 = 24
f. R7 = 43
Now you’re going to define the G variables in the same manner as you did
above for the resistor values.
11
• G6=1/R6;
• G7=1/R7;
12
3.2 Creating Matrices
This section will guide you through creating a matrix in Matlab and then show
you how to solve the system of equations presented at the beginning of the
chapter.
R1 R2
R R4
3
Figure 22. A matrix.
13
CHAPTER 4
The following function is going to be plotted with three different values of R all on the
same plot.
I 2*
v(t) = * * exp( * t) * sin( d * t) * u(t)
G 1 2
I is current.
G is the inverse of resistance (1/R).
is the greek letter for zeta.
is the attenuation coefficient
d is the frequency in radians/sec.
14
Figure 26. All variables defined.
15
4.2 Creating Graphs
1. To create a graph, view the graph toolbar (ViewToolbarsGraph) and click
on 2-D graph
You can also use the keyboard shortcut Shift+2 for a 2-D graph.
2. Once you click on 2-D graph you will get the following
The middle placeholder on the x and y-axis is for defining the axis. The
placeholders outside of the middle one are for defining the range of that axis
16
Figure 29. X-axis defined.
o To get multiple functions on the same graph, first place the cursor
in the middle placeholder.
o Then enter v(t,3*k)
o Hit comma on the keyboard
o Another placeholder will appear to enter the second function
o Enter v(t,1*k) followed by a comma
o Enter v(t, 500*)
17
Figure 31. Damped sine plots.
18
Figure 32. Damped sine plots with labels.
Close Mathcad.
19
CHAPTER 5
The following function is going to be plotted with three different values of R all on the
same plot.
I is current. G is the inverse of resistance (1/R). is the greek letter for zeta. is the
attenuation coefficient. d is the frequency in radians/sec.
19
For definition of
5.2 Creating Graph linspace type help
linspace in matlab
• First define the vector t for the time variable as shown below window or look in
the glossary.
• Do the following in the figure below to graph all 3 functions on one graph
20
Figure 37. Damped sine waves.
21
Figure 39. Damped sine wave plot with labels.
Close Matlab.
22
CHAPTER 6
Bode plots are used to plot the magnitude and phase of transfer functions in decibels and
degrees of frequency. The magnitude is also considered the gain of the function, which is
plotted on a linear scale. The frequency is plotted on a log scale.
23
Figure 41. Transfer function defined.
24
6.2 Creating Vectors
Instead of using the default number of points like we did in the last chapter, we
are going to create a frequency vector.
i is an array. Keyboard
shortcut for this is i, colon,
0, semicolon, N-1
25
6.3 Creating Bode Plot
1. Start the 2D graph by the shortcut shift+2
2. Set the x-axis as shown below
26
Figure 46. The plot on a linear scale.
5. Place the pointer on the graph and double click. This will appear
27
Figure 48. The bode plot with a log scale.
Now we’re going to add the phase function to the same plot.
1. Double click on the plot
2. Check the box to enable the secondary y-axis
28
3. Click Ok and the following will appear
29
Figure 52. Magnitude and phase plot.
If you want, you can add labels to your plot in the same manner that was done in Chapter
4.3.
Close Mathcad.
30
CHAPTER 7
Bode plots are used to plot the magnitude and phase of transfer functions in decibels and
degrees of frequency. The magnitude is also considered the gain of the function, which is
plotted on a linear scale. The frequency is plotted on a log scale.
In Mathcad, the bode plot was made in a 2D graph. In Matlab there is a built in function
called bode that will automatically plot the graph.
31
7.2 Defining Transfer Functions
In Matlab there is a built-in function that evaluates transfer functions. This built-
in function is tf(X,Y). X and Y are the parameters of the function. X is the
numerator and Y is the denominator.
Define the following in Matlab to evaluate the three transfer functions that will be
plotted
Each of the values in the array for N, D1, D2, D3 are the coefficients of s from
highest power to lowest.
32
7.3 Creating Bode Plots
Do the following to plot the transfer functions
33
7.4 Changing Units
To change the units double click on the plot and the following will appear.
34
Figure 58. Bode plot with frequency in Hz.
35
CHAPTER 8
Troubleshooting
Solution: This means that the inner dimensions of the matrices that you’re trying
to multiply don’t match. When you multiply matrices place a period before the
asterisk.
Solution: Make sure your variable is defined before you use it. It needs to be
above where you use it. Also make sure that it is the right case. Both Matlab and
Mathcad are case sensitive.
36
8.3 Problems With Units in Mathcad
Problem: You defined variables with units and some without. This then leads to
an error in an equation that uses a combination of those variables.
Solution: When you add units to variables, Mathcad will check to make sure the
units match when you use those variables. Either add units to all of your variables
or remove the units from all of the variables to get rid of the error message.
37
APPENDIX A
Glossary
B
Bode(sys)
Bode is a built in function in Matlab that draws the bode plot of the linear-time-
invariant system sys.
Bode Plot
Consists of a magnitude and phase plot. The magnitude plot is a plot of log
magnitude versus frequency of a complex transfer function. The frequency is a
log scale. The magnitude is measured in decibels (20*log(gain)). The phase plot is
a function of the phase versus frequency, also plotted on a log-frequency axis.
The phase plot is used to show home much the transfer function is shifted.
C
Conductance (G)
It is the inverse of resistance (R).
Current
Flow of electric charge. Symbolized by I or i. Measured in Amps.
D
Defining Variables in Mathcad
To define variables in Mathcad:
Choose the variable (e.g. R)
Enter the variable (e.g. R) + colon or select := on the evaluation toolbar.
38
Enter the value for the variable
Ex. Define R = 100.
Keyboard sequence for this would be R, colon, 100.
Evaluation Toolbar
To display the evaluation toolbar, go to viewToolbarsEvaluation
G
Greek Toolbar
In Mathcad it is the toolbar with all the greek symbols in lowercase and
uppercase. It looks like the following
39
I
inv()
This Matlab built-in function calculates the inverse of the inputted argument.
L
Linear Time Invariant System
LTI system theory examines the response of a linear, time-invariant system to an
arbitrary input signal. LTI systems can be characterized by the system’s transfer
function. The system’s transfer function is the Laplace transform of the system’s
impulse response.
Linspace
Linearly spaced vector.
LINSPACE(X1, X2) generates a row vector of 100 linearly
equally spaced points between X1 and X2.
S
Sqrt(x)
Built in function in matlab that calculates the square root of x.
T
tf(N,D)
tf(N,D) creates a continuous-time transfer function with numerator N and
denominator D.
N is a vector with the coefficients of s in the numerator from highest to lowest
power.
40
D is a vector with the coefficients of s in the denominator from highest to lowest
power.
title(“x”)
Built in Matlab function that adds a title to a figure.
Transfer Function
A mathematical representation of the relation between the input and output of a
(linear time-invariant) system.
V
Voltage
Difference of electric potential between two points of an electric circuit and is
measured in volts (V).
X
Xlabel()
Built-in Matlab function that labels the x-axis.
Y
Ylabel()
Built-in Matlab function that labels the y-axis.
41