12-11-2016, 09:49 AM
1474628872-SALab1.doc (Size: 407 KB / Downloads: 4)
Introduction: MATLAB is an environment for performing calculations and simulations of a variety of types. MATLAB, short for matrix laboratory, was developed and founded MathWorks by Cleve Moler, a professor of mathematics and computer science. In the earliest version of MATLAB, there were about 80 commands, and they allowed for matrix calculations. Now there are thousands of commands, and there are many, many types of calculations that one can perform. During the course of this lab, the student will learn how to make calculations using MATLAB and will learn a little about simulating systems using the simulation tools provided by MATLAB.
Objectives:
1. To familiar with the Matlab environment.
2. Write the simple Matlab code to perform certain operations.
Requirements: Digital Computer with MATLAB software.
MATLAB (short for MATrix LABoratory) is a powerful computing environment that handles anything from simple arithmetic to advanced data analysis. At its core is the matrix as its basic data type. Combined with extensive maths and graphics functions, complicated calculations can be carried out by specifying only a few simple instructions. MATLAB can be used to do anything your scientific calculator can do, and more. The installations in the computer labs include tool boxes that include functions for electrical engineering related tasks, such as signal processing and system analysis. The installations in the computer labs include tool boxes that include functions for electrical engineering related tasks, such as signal processing and system analysis. You can plot your data in a multitude of visualizations as well. Matlab is basically a high level language which has many specialized toolboxes for making things easier for us
Computations can be carried out in one of three ways:
1. Directly from the command line,
2. by writing a script that carries out predefined instructions, or
3. by writing your own functions.
Writing your own functions is much like programming in other languages, except that you have the full resources of MATLAB's functions at your disposal, making for very compact code. The MATLAB-6 and above environment has several windows at your disposal.
Command Window: The main window is the command window, where you will type all your commands, for small programs.
1. Definition of Vectors & Matrices: MATLAB is based on matrix and vector algebra; even scalars are treated as 1x1 matrices. Therefore, vector and matrix operations are as simple as common calculator operations. Vectors can be defined in two ways.
Method1: The first method is used for arbitrary elements:
>> v = [1 3 5 7]; %creates a 1x4 vector with elements 1,3, 5 and 7.
* Note that commas could have been used in place of spaces to separate the elements. that is
>> v = [1,3,5,7];
• Additional elements can be added to the vector:
>> v(5) = 8 % yields the vector v = [1 3 5 7 8].
Previously defined vectors can be used to define a new vector. For example, with ' v ' defined above
>> a = [9 10];
>> b = [v a] % creates the vector b = [1 3 5 7 8 9 10].
Method2: The second method is used for creating vectors with equally spaced elements:
t = 0: 0.1:10 % creates a 1x101 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: For example.
k = 0:10 % creates a 1x11 vector with the elements 0, 1, 2, ..., 10.
2. Matrices: Matrices are defined by entering the elements row by row
>> M = [1 2 4; 3 6 8; 2 6 5] % creates a 3X3 matrix
>> M' % Transpose of matrix M
*The inverse of M is M-1 denoted in Matlab as M^-1
>> M^-1
>> M(2,3) % displays the element of second row and third column
3. Arithmetic Operations: When applying addition, subtraction, multiplica-tion and division between a scalar (that is a single number) and a vector we use +, -, *, and / respectively.
% Let
>> a = [1 2 3;4 5 6;7 8 9]
>> b = [9 8 7;6 5 4;3 2 1]
% Then
>> a + b % addition of two matrices
>> a - b % Subtraction of two matrices
>> a*b % Multiplication
>> a+2 % addition of a constant to matrix ‘a ‘
>> a .*b % Element wise multiplication
OUT PUT:
> a = [1 2 3;4 5 6;7 8 9]
a =
1 2 3
4 5 6
7 8 9
K>> b = [9 8 7;6 5 4;3 2 1]
b =
11. Using Matlab Editors : Very small programs can be typed and executed in command window. Large programs on other hand can be used the Matlab editor. The complete program can be typed in the Matlab editor and saved as 'file_name.m', and can be retrieved when-ever necessary. You can execute either directly from editor window or type the file_name in the command window and press the enter button.