0% found this document useful (0 votes)
52 views4 pages

Bahria University Karachi Campus: Matrix Generation & Matrix Operations

This document provides instructions for a MATLAB lab experiment on matrix generation and operations. The objective is to familiarize students with basic MATLAB functionality including declaring matrices, performing operations to manipulate them, and using built-in functions. The document explains how to enter and exit MATLAB, create row and column vectors and matrices, perform arithmetic operations on them, and generate graphs by plotting data. It includes example code and questions for students to investigate effects of commands and implement matrix operations and built-in functions in MATLAB.

Uploaded by

Usman Ghani
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)
52 views4 pages

Bahria University Karachi Campus: Matrix Generation & Matrix Operations

This document provides instructions for a MATLAB lab experiment on matrix generation and operations. The objective is to familiarize students with basic MATLAB functionality including declaring matrices, performing operations to manipulate them, and using built-in functions. The document explains how to enter and exit MATLAB, create row and column vectors and matrices, perform arithmetic operations on them, and generate graphs by plotting data. It includes example code and questions for students to investigate effects of commands and implement matrix operations and built-in functions in MATLAB.

Uploaded by

Usman Ghani
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/ 4

LAB-2

BAHRIA UNIVERSITY KARACHI CAMPUS


Department of Electrical Engineering

SIGNALS & SYSTEMS

LAB EXPERIMENT # 2

Matrix Generation & Matrix Operations

OBJECTIVE:-
The purpose of this lab is to familiarize you with basic MATLAB functionality. The tasks include

 To become familiar with MATLAB


 Declaring matrices in MATLAB command window.
 Performing various matrix operations, to manipulate them.

TOOLS:-

 MATLAB R-2006a or higher version

THEORY:-
The name MATLAB is short for MATrix LABoratory. It is a commercial software package whose
main function is to perform calculations on matrices, row vectors and column vectors. It is widely
used in both industry and academic institutions. It possesses many of the features of a high level,
numerically oriented programming language, and it has a large collection of built-in functions for
performing matrix and vector operations in a way that is very simple for the user. For example, to
find the determinant of a matrix A one needs only enter: det(A)

Entering and quitting MATLAB


To enter MATLAB, simply double click on the MATLAB icon. To leave MATLAB and return to the
PC’s operating system simply type: quit

6
LAB-2

Creating and manipulating matrices and vector


MATLAB works on matrices and vectors that may be real or complex. Variables do not have to be
“declared”. Results can be displayed in a variety of different formats.
Let us enter a row vector into the MATLAB workspace. Type in:

>> v = [2 4 7 5]
This creates a variable v whose current value is a row vector with four elements as shown. After
pressing “return” the value of v will be echoed back to you. To suppress the echo, one uses a semi-
colon following the command line. Thus

>> w = [1 3 8 9];

Creates another row vector w, but does not echo. To check that w has appeared in the MATLAB
workspace, type, >> who
Which will display all the variables in the MATLAB workspace, and to check the value of w simply
type w. Operations on row vectors can be best illustrated by some simple exercises.

One way to generate a column vector is to take the transpose of a row vector. Column vectors can be
typed in directly in one of two ways. For example, to enter the command vector

1 
1 
z 
0 
 
0 

you can type

>> z = [1; 1; 0; 0]; or >> z= [1 2 0 0]’

One way of creating matrices is by multiplying row and column vectors as seen in the above
exercises. There are various ways of entering matrices. For example, to enter the matrix
1 2
M 
3 4
The most obvious ways are to type
>> M = [1 2; 3 4]; or >> M = [[1 3]’[2 4]’];

Built-in Functions
You have already encountered some built-in functions. In addition to standard arithmetic operators,
such as “+” and “*”, you have inv(A) that generates the inverse of matrix A, and eye(n) that
7
LAB-2

generates the n-by-n identity matrix. MATLAB has a very large number of built-in functions. To see
the full list of those variables on your machine type help, to get information on a specific function
(“inv” for example) type: help inv. The help command is very useful, most of the MATLAB built-in
functions have very descriptive names and are easily remembered or guessed.

Graphs
The results of signal processing computations in MATLAB are huge matrices containing, for
example, frequency responses, which one would like to display in graphical form. We will go
through a simple example of generating data, plotting the graph, putting labels on the axes etc.
We will plot the graph of y = sin(t), for t going from 0 to 20 seconds. First we need to generate a
vector t containing the values of time that we want to use. Type:
>> t=linspace(0,20,100);
It makes t into a row vector of 100 values from 0 to 20 inclusive, then type:
>> ys = sin(t);
To plot the set of points type:
>> Plot(t,ys)
The basic graph can be prettied up using the following self explanatory sequence of commands:

>> xlabel(‘Time in seconds’)


>> ylabel(‘sin(t)’)
>> title(‘your Roll No.’)
>> grid

More than one set of points can be plotted on the same axes, and more than one graph can be
displayed on the screen at once. The following exercise leads you though this:

8
LAB-2

QUESTIONS:-

1. Investigate the effect of the following commands:


(a) v(2) (b) sum = v + w (c) diff = v – w (d) vw = [v w] (e) vw(2: 6) (f) v’

2. Investigate the effect of the following commands:


(a) z’ (b) z*v (c) [v; w] (d) v*z (e) [z; v’] (f) z + v’

3. Implement the following commands in MATLAB:


(a) N = inv(M) (b) M*N (c) I = eye(2) (d) M + I (e) M*z(1:2) (f) v(3:4)*M
(g) M(1,1) (h) M(1:2,1:2) (i) M(:,1) (j) M(2,:)

4. Use the following buit-in MATLAB function:


(a). ones (b). zeros (c). det (d). Linspace (e). Logspace

OBSERVATION:- Attach the prints of the plots you obtain in the exercises above.

You might also like