Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

LINEAR CONTROL SYSTEMS LAB Name __________________________________

Roll No. _____________________________

Experiment # 1 Introduction to MATLAB

Objective

Give a detail Introduction to MATLAB.


The name MATLAB stands for MATRIX laboratory. MATLAB was written originally to
provide easy access to matrix software developed by the LINPACK (linear system
package) and EISPACK (Eigen system package) projects. MATLAB is a high-performance
language for technical computing. It integrates computation, visualization, and
programming environment. Furthermore, MATLAB is a modern programming language
environment; it has sophisticated data structures, contains built-in editing and debugging
tools, and supports object-oriented programming. These factors make MATLAB an
excellent tool for teaching and research.

MATLAB is a high-performance language for technical computing. It integrates


computation, visualization, and programming in an easy-to-use environment where
problems and solutions are expressed in familiar mathematical notation. Typical uses
include:

 Math and computation


 Algorithm development
 Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics

Experiment 1 Introduction to MATLAB Page 1 of 13


LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________

Application development, including Graphical User Interface building MATLAB is an


interactive system whose basic data element is an array that does not require dimensioning.
This allows you to solve many technical computing problems, especially those with matrix
and vector formulations, in a fraction of the time it would take to write a program in a
scalar non interactive language such as C or Fortran. The name MATLAB stands for matrix
laboratory. MATLAB was originally written to provide easy access to matrix software
developed by the LINPACK and EISPACK projects, which together represent the state-of-
the-art in software for matrix computation.

The MATLAB System

 The MATLAB system consists of five main parts:


 The MATLAB Application Program Interface (API)
 The MATLAB mathematical function library
Experiment 1 Introduction to MATLAB Page 2 of 13
LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________
 Handle Graphics
 The MATLAB working environment
 The MATLAB language

The MATLAB working environment

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.

Useful functions and operations in MATLAB

Here is a table of useful operations, functions and constants in MATLAB.

Experiment 1 Introduction to MATLAB Page 3 of 13


LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________

The following commands are useful when plotting:

Experiment 1 Introduction to MATLAB Page 4 of 13


LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________

The MATLAB mathematical function library

This is a vast collection of computational algorithms ranging from elementary functions


like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix
inverse, matrix Eigen values, Bessel functions, and fast Fourier transforms.

Advantages of MATLAB

MATLAB has many advantages compared to conventional computer languages (e.g.,C,


FORTRAN) for solving technical problems.

 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( )

>> round(58.78888) %round off the floating points%


ans = 59
 Eye( )

>> eye(4,4) %gives identity matrix of order n x m%

Experiment 1 Introduction to MATLAB Page 7 of 13


LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________
ans =1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

 Zeros( )

>> zeros(2,3) %gives a matrix of zeros of order n x m%


ans =0 0 0
0 0 0
 Ones( )

>> ones(4,3) %gives a matrix of ones of order n x m%


ans = 1 1 1
1 1 1
1 1 1
1 1 1
 Row Mtrix

>> x=[1,2,3,4,5] %gives row matrix%


x =1 2 3 4 5
 Column Matrix

>> y=[1;2;3;4;5] %gives column matrix%


y =1
2
3
4
5
 Order

>> c=[1 2 3 4;5 6 7 8] %gives a matrix of order 4 x 4%


c =1 2 3 4
5 6 7 8
 clc
Experiment 1 Introduction to MATLAB Page 8 of 13
LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________
clc %clears command window%
This command clears the command window on matlab
 clear or clear all

Clear %clears all the command history%


Clears the command window and command history
Plotting on Matlab
MATLAB has an excellent set of graphic tools. Plotting a given data set or the results of
computation is possible with very few commands.
The plot function has different forms depending on the input arguments. If y is a vector
plot(y) produces a piecewise linear graph of the elements of y versus the index of the
elements of y. If we specify two vectors, as mentioned above, plot(x,y) produces a graph of
y versus x. The basic MATLAB graphing procedure, for example in 2D, is to take a vector
of x-coordinates, x = (x1; : : : ; xn), and a vector of y-coordinates, y = (y1; : : : ; yn), locate
the points (xi; yi), with
i = 1; 2; : : : ; n and then join them by straight lines. You need to prepare x and y in an
identical array form; namely, x and y are both row arrays or column arrays of the same
length.
 Plot(x,y)

>> 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

Experiment 1 Introduction to MATLAB Page 9 of 13


LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________
 Step Size

Formula to calculate Step size is as follows.

Step size = (final value – initial value) / no of samples

>> f=50

f= 50

>> t=-0.1: (0.1-(-0.1))/8000:0.1;

>> sin(2*pi*50*t);

>> plot(sin(2*pi*100*t))

Fig 1.2 Plotting of Sinusoidal Signal

 Grid

This function Defines the axis by providing grids to the graph

 Label

MATLAB enables you to add axis labels and titles. For example, using the graph from the

previous example, add an x- and y-axis labels.

Experiment 1 Introduction to MATLAB Page 10 of 13


LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________
We label the axis on Matlab as

Xlabel( );

Ylabel( );

Title( );

 Xlabel

The x label defines the x-axis. Implemented on MATLA

>>xlabel(0:2π)

 Ylabel

Ylabel defines the y-axis implemented on MATLAB as.

>> ylabel('Sine of x');

 Title

Gives the title to the graph or signal in MATLAB

>> title('Plot of the Sine function')

Fig 1.3 Different Labeling

Experiment 1 Introduction to MATLAB Page 11 of 13


LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________

 Stem

This command provides the dicrete version of the signal

For example

> > x=5*ones(length(n),1);

>> n=(0:4);

>> plot(n,x )

>> stem(n,x)

Fig 1.4 Discrete plotting

Experiment 1 Introduction to MATLAB Page 12 of 13


LINEAR CONTROL SYSTEMS LAB Name __________________________________
Roll No. _____________________________

Checked by: Date:

Experiment 1 Introduction to MATLAB Page 13 of 13

You might also like