0% found this document useful (0 votes)
13 views7 pages

Laboratory Activity 1 - Introduction To MATLAB-2

The document is a laboratory experiment manual for an introductory MATLAB course, outlining objectives, discussions on MATLAB's capabilities, and basic commands for numerical computation and visualization. It includes procedures for various mathematical operations, vector and matrix manipulations, and examples of predefined functions. Additionally, it provides equipment requirements and questions for students to explore MATLAB's functionalities further.

Uploaded by

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

Laboratory Activity 1 - Introduction To MATLAB-2

The document is a laboratory experiment manual for an introductory MATLAB course, outlining objectives, discussions on MATLAB's capabilities, and basic commands for numerical computation and visualization. It includes procedures for various mathematical operations, vector and matrix manipulations, and examples of predefined functions. Additionally, it provides equipment requirements and questions for students to explore MATLAB's functionalities further.

Uploaded by

matthewlim1019
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

DE LA SALLE LIPA

COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING


COMPUTER ENGINEERING DEPARTMENT
DIGISIG – DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT MANUAL

EXPERIMENT #1: INTRODUCTION TO MATLAB

I. OBJECTIVES
1. To be familiarized with MATLAB syntax and basic commands
2. To use MATLAB on performing basic mathematical operations

II. DISCUSSION
MATLAB is a high-level language and interactive environment for
numerical computation, visualization, and programming.
Using MATLAB, you can analyze data, develop algorithms, and create
models and applications. The language, tools, and built-in math functions
enable users to explore multiple approaches and reach a solution faster than
with spreadsheets or traditional programming languages such as C/C++ or
Java.
MATLAB can be used for a wide range of applications, including signal
processing and communications, image and video processing, control
systems, test and measurement, computational finance, and computational
biology.
The name MATLAB is a contraction of “Matrix Laboratory”. MATLAB is a
product of MathWorks.
MATLAB is started by clicking the mouse on the MATLAB icon and is
ended by typing exit or by using the menu option. After each MATLAB
command, the "return" or "enter" key must be depressed.
Variables are assigned numerical values by typing the expression directly.
Example: Type a = 1+2 in the MATLAB Command Window and then press
Enter.
The answer will not be displayed when a semicolon is put at the end of an
expression. Example: Type a = 1+2; and then press Enter.
MATLAB utilizes the following arithmetic operators:
+ addition

1
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
DIGISIG – DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT MANUAL

- subtraction
* multiplication
/ division
^ power operator
' transpose
A variable can be assigned using a formula that utilizes these operators
and either numbers or previously defined variables. Example: b = 2*a. Note
that a is defined previously.
To determine the value of a previously defined quantity, type the quantity
itself. Example: Type b and press Enter.
If the expression does not fit on one line, use an ellipsis (three or more
periods at the end of the line) and continue on the next line.
Note that the ellipsis must come after an operator.
Example: c = 1+2+3+...
5+6+7;
Some predefined variables which can be used in the same manner as
user-defined variables:
i as sqrt(-1)
j as sqrt(-1)
pi as 3.1416...
Example: y= 2*(1+4*j)
Some predefined functions that can be used when defining a variable:

abs - magnitude of a number (absolute value for real numbers)

angle - angle of a complex number, in radians

cos - cosine function, assumes argument is in radians

sin - sine function, assumes argument is in radians

exp - exponential function

2
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
DIGISIG – DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT MANUAL

Examples:
c = abs(y)
c = angle(y)
c = cos(a)
c = exp(a)
Note that exp can be used on complex numbers.
Example: c = exp(y)
MATLAB is based on matrix and vector algebra. A scalar is treated as the
element of a 1x1 matrix. Vectors can be defined in two ways.
The first method is used for arbitrary elements.
Example: v = [1 3 5 7]
Note that the previous example creates a 4-element vector with elements
1, 3, 5, and 7. Note that commas may be used in place of spaces to separate
the elements. Additional elements can be added to the vector.
Example: v(5) = 8
The previous example gives v = [1 3 5 7 8].
Previously defined vectors can be used to define a new vector.
Example: a = [9 10]; b = [v a];
The previous example creates vector b = [1 3 5 7 8 9 10].
The second method is used for creating vectors with equally spaced
elements. Example: t = 0:.1:10;
The previous example creates a 101-element vector with the elements 0,
.1, .2, .3,...,10. Note that the middle number defines the increment. If only two
numbers are given, then the increment is set to a default of 1. Example: k =
0:10;
The previous example creates an 11-element vector with the elements 0,
1, 2, ..., 10.
Matrices are defined by entering the elements row by row.
Example: M = [1 2 4; 3 6 8];

3
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
DIGISIG – DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT MANUAL

The previous example creates a 2x3 matrix.


Some special matrices that can be defined:
null matrix: M = [ ];
mxn matrix of zeros: M = zeros(m,n);
mxn matrix of ones: M = ones(m,n);
nxn identity matrix: M = eye(n);
A particular element of a matrix can be assigned. Example: M(1,2) = 5;
The previous example places the number 5 in the first row, second
column.
Operations on matrices:
a = [1 2 3];
b = [4 5 6];
c=a+b
The previous set of commands give c = 5 7 9.
Functions are applied element by element. Example: t = 0:10; x = cos(2*t);
The previous example creates a vector x with elements equal to cos(2t)
for t = 0, 1, 2, ..., 10.
Operations that need to be performed element-by-element can be
accomplished by preceding the operation by a ".". Example: t = 0:10; x =
t.*cos(t);
MATLAB is case sensitive (a and A are different).
Comment statements are preceded by a "%".
On-line help for MATLAB can be reached by typing help for the full menu
or typing help followed by a particular function name or M-file name. Example:
help cos gives help on the cosine function.
The number of digits displayed is not related to the accuracy.
To change the format of the display, type format short e for scientific
notation with 4 decimal places, format long e for scientific notation with 15

4
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
DIGISIG – DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT MANUAL

significant decimal places and format bank for placing two significant digits to
the right of the decimal.
The commands who and whos give the names of the variables that have
been defined in the workspace.
The command length(x) returns the length of a vector x and size(x) returns
the dimension of the matrix x.
M-files are macros of MATLAB commands that are stored as ordinary text
files with the extension "m", that is filename.m. An M-file can be either a
function with input and output variables or a list of commands. MATLAB
requires that the M-file must be stored either in the working directory or in a
directory that is specified in the MATLAB path list.

III. EQUIPMENT NEEDED


ITEM NO. DESCRIPTION QUANTITY
MATLAB 2014 1 per student

IV. PROCEDURE
1. Create a vector of the even whole numbers between 31 and 75.
2. Let x = [2 5 1 6].
a. Add 16 to each element
b. Add 3 to just the odd-index elements
c. Compute the square root of each element
d. Compute the square of each element
3. Let x = [3 2 6 8]' and y = [4 1 3 5]' (x and y should be column vectors).
a. Add the sum of the elements in x to y
b. Raise each element of x to the power specified by the corresponding
element in y.
c. Divide each element of y by the corresponding element in x.

5
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
DIGISIG – DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT MANUAL

d. Multiply each element in x by the corresponding element in y, calling


the result "z".
e. Add up the elements in z and assign the result to a variable called "w".
4. Write down the MATLAB expression(s) that will
a. compute the length of the hypotenuse of a right triangle given the
lengths of the sides (try to do this for a vector of side-length values).
b. compute the length of the third side of a triangle given the lengths of
the other two sides, given the cosine rule c2 = a2 + b2 - 2(a)(b)cos(t)
5. Given a vector, t, of length n, write down the MATLAB expressions that
will correctly compute the following:
a. ln(2 + t + t2)
b. et(1 + cos(3t))
c. cos2(t) + sin2(t)
d. tan-1(1)
e. cot(t)
f. sec2(t) + cot(t) – 1
Test that your solution works for t = 1:0.2:2

V. QUESTIONS
1. From procedure 3, compute x'*y - w and interpret the result.
2. Make a good plot of the function f(x) = sin(1/x) for 0.01 < x < 0.1. How did
you create x so that the plot will look good?
3. Plot the expression (determined in modelling the growth of the US
population) P(t) = 197,273,000/(1 + e-0.0313(t - 1913.25)) where t is the date, in
years AD, using t = 1790 to 2000. What population is predicted in the year
2020?

6
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
DIGISIG – DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT MANUAL

VI. CONCLUSION

Reference:
http://www.cogsci.ucsd.edu/~ajyu/Teaching/CogSci_bootcamp08/matlab_ex.html

You might also like