Experiment # 1 Introduction To MATLAB Objective
Experiment # 1 Introduction To MATLAB Objective
Experiment # 1 Introduction To MATLAB Objective
Objective
This is the set of tools and facilities that you work with as the MATLAB user or
programmer. It includes facilities for managing the variables in your workspace and
importing and exporting data. It also includes tools for developing, managing, debugging,
and profiling M-files, MATLAB's applications.
Handle Graphics
This is the MATLAB graphics system. It includes high-level commands for two-
dimensional and three-dimensional data visualization, image processing, animation, and
presentation graphics. It also includes low-level commands that allow you to fully
customize the appearance of graphics as well as to build complete Graphical User
Interfaces on your MATLAB applications.
Advantages of MATLAB
MATLAB is an interactive system whose basic data element is an array that does
not
Require any dimensions.
The software package as been commercially available since 1984 and is now
considered as a standard tool at most universities and industries worldwide.
It has powerful built-in routines that enable a very wide variety of computations. It
also has easy to use graphics commands that make the visualization of results
immediately available. Special applications are collected in packages referred to as
toolbox.
There are toolboxes for signal processing, symbolic computation, control theory,
simulation, optimization, and several other Fields of applied science and
engineering.
Experiment 1 Introduction to MATLAB Page 5 of 13
LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________
Starting With MATLAB
After logging into your account, you can enter MATLAB by double-clicking on the
MATLAB Short cut icon (MATLAB 7.0.4) on your Windows desktop. When you start
MATLAB, a special window called the MATLAB desktop appears. The desktop is a
window that contains other windows. The major tools within or accessible from the desktop
are:
The Command Window
The Command History
The Workspace
The Current Directory
The Help Browsing
The Start button
Error Message
If we enter an expression incorrectly, MATLAB will return an error message. For example,
>> c=[1,2,3;4,5,6,7]
??? Error using ==> vertcat
All rows in the bracketed expression must have the same number of columns.
Controlling the hierarchy of operations or precedence
Let's consider the previous arithmetic operation, but now we will include parentheses. For
example, 1 + 2 *3 will become (1 + 2) * 3
>> (1+2)*3
ans = 9
and, from previous example >> 1+2*3
ans =7
By adding parentheses, these two expressions give different results: 9 and 7.The order in
which MATLAB performs arithmetic operations is exactly that taught in high school
algebra courses. Exponentiations are done, followed by multiplications and divisions, and
mathematical by additions and subtractions. However, the standard order of precedence of
arithmetic operations can be changed by inserting parentheses. For example, the result of
1+2 x 3 is quite different than the similar expression with parentheses
(1+2)*3.
Experiment 1 Introduction to MATLAB Page 6 of 13
LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________
The results are 7 and 9 respectively. Parentheses can always be used to overrule priority,
and their use is recommended in some complex expressions to avoid ambiguity. Therefore,
to make the evaluation of expressions unambiguous, MATLAB has established a series of
rules. The order in which the arithmetic operations are evaluated is given in Table 1.2.
MATLAB arithmetic operators obey the same precedence rules as those in most computer
programs. For operators of equal precedence, evaluation is from left to right.
Now, consider another example:
1/2+3^2 +4/5 X 6/7
In MATLAB, it becomes
>> 1/(2+3^2)+4/5*6/7
ans = 0.7766
or, if parentheses are missing,
>> 1/2+3^2+4/5*6/7
ans = 10.1857
So here what we get: two different results. Therefore, we want to emphasize the importance
of precedence rule in order to avoid ambiguity.
Commands on Matlab
The following commands are used on the Matlab command window to implement the
codes
Rand( ) %gives a matrix of order n x m%
>> rand(3,4)
ans =
0.9501 0.4860 0.4565 0.4447
0.2311 0.8913 0.0185 0.6154
0.6068 0.7621 0.8214 0.7919
Round( )
Zeros( )
>> x = [1 2 3 4 5 6];
y = [3 -1 2 4 5 1];
>> plot(x,y)
Fig 1.1 Plotting of a random mat
>> f=50
f= 50
>> sin(2*pi*50*t);
>> plot(sin(2*pi*100*t))
Grid
Label
MATLAB enables you to add axis labels and titles. For example, using the graph from the
Xlabel( );
Ylabel( );
Title( );
Xlabel
>>xlabel(0:2π)
Ylabel
Title
Stem
For example
>> n=(0:4);
>> plot(n,x )
>> stem(n,x)