SlideShare uma empresa Scribd logo
1 de 79
Baixar para ler offline
1




C Language is Simplest.
2




What may be the size of the program for
writing a C code that generates sin
wave?
3




But we can do the same by only three
lines.
x=0.1:0.1:10;
                4
b=sin(x);
Plot(x,b)
------ no
computational
complexity
5

That is the beauty we have as an
engineer.

Name is

                MATLAB
Recent Trends in Computational
        techniques for Engineering

                            6


           Use of MATLAB in
           Engineering
Prof. Ashish M. Kothari
Department of Electronics & Communication Engineering
Atmiya Institute of Technology & Science, Rajkot
Topics..
                         7

What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
Plotting functions ..
Topics..
                         8

What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
Plotting functions
MATLAB
                      9


“MATrix LABoratory”

Powerful, extensible, highly integrated
computation, programming, visualization, and
simulation package

Widely used in engineering, mathematics, and
science
MATLAB
                10




Everything in MATLAB is a matrix !
MATLAB- Starting & Quiting
                                    11



Starting MATLAB
On a Microsoft Windows platform, to start MATLAB, double-click the
MATLAB shortcut icon on your Windows desktop.

On Linux, to start MATLAB, type matlab at the operating system prompt.

After starting MATLAB, the MATLAB desktop opens – see “MATLAB
Desktop”.

You can change the directory in which MATLAB starts, define startup
options including running a script upon startup, and reduce startup time in
some situations.
MATLAB- Starting & Quiting
                          12



Quiting MATLAB

To end your MATLAB session, select Exit MATLAB from the
File menu in the desktop, or type quit in the Command
Window.
The MATLAB Desktop
        13
MATLAB Variable
                            15

Variable names ARE case sensitive

Variable names can contain up to 63 characters (as of
MATLAB 6.5 and newer)

Variable names must start with a letter followed by letters,
digits, and underscores.
MATLAB Variable
                               16


>> 16 + 24                 no declarations needed
ans =
    40

>> product = 16 * 23.24                    mixed data types
product =
       371.84

                                    semi-colon suppresses output of
>> product = 16 *555.24;            the calculation’s result
>> product
product =
       8883.8
MATLAB Variable
                                 17
>> clear                             clear removes all variables;
>> product = 2 * 3^3;
>> comp_sum = (2 + 3i) + (2 - 3i); clear x y removes only x and y
>> show_i = i^2;
                                complex numbers (i or j) require
>> save three_things
                                no special handling
>> clear
>> load three_things
>> who
                                  save/load are used to
Your variables are:
comp_sum product    show_i        retain/restore workspace variables
>> product
product =
    54
                              use home to clear screen and put
>> show_i
                              cursor at the top of the screen
show_i =
    -1
MATLAB Special Variables
                        18

ans       Default variable name for results
pi        Value of π
eps       Smallest incremental number
inf       Infinity
NaN       Not a number e.g. 0/0
i and j   i = j = square root of -1
realmin   The smallest usable positive real number
realmax   The largest usable positive real number
Topics..
                         19

What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
Plotting functions ..
Math & Assignment Operators
                         20

Power             ^ or .^ e.g   a^b    or       a.^b
Multiplication    * or .* e.g   a*b    or       a.*b
Division          / or ./ e.g   a/b    or       a./b
  or               or . e.g   ba    or       b.a
  NOTE:           56/8 = 856



 - (unary) + (unary)
 Addition      +        a+b
 Subtraction -          a-b
 Assignment =           a=b   (assign b to a)
Other MATLAB symbols
                     21




>>      prompt
...     continue statement on next line
,       separate statements and data
%       start comment which ends at end of line
;       (1) suppress output
        (2) used as a row separator in a matrix
:       specify range
MATLAB Relational Operators
                        22

MATLAB supports six relational operators.

Less Than                    <
Less Than or Equal           <=
Greater Than                 >
Greater Than or Equal        >=
Equal To                     ==
Not Equal To                 ~=
MATLAB Logical Operators
                      23




MATLAB supports three logical operators.

not      ~      % highest precedence
and      &      % equal precedence with or
or       |      % equal precedence with and
MATLAB Matrices
                            24

MATLAB treats all variables as matrices. For our purposes
a matrix can be thought of as an array, in fact, that is how
it is stored.

Vectors are special forms of matrices and contain only one
row OR one column.

Scalars are matrices with only one row AND one column
MATLAB Matrices
                            25

  A matrix with only one row AND one column is a scalar. A
  scalar can be created in MATLAB as follows:

» a_value=23

a_value =

 23
MATLAB Matrices
                             26

  A matrix with only one row is called a row vector. A row
  vector can be created in MATLAB as follows (note the
  commas):

» rowvec = [12 , 14 , 63]

rowvec =

  12 14 63
MATLAB Matrices
                             27


   A matrix with only one column is called a column vector.
   A column vector can be created in MATLAB as follows
   (note the semicolons):

» colvec = [13 ; 45 ; -2]

colvec =

  13
  45
  -2
MATLAB Matrices
                                   28

   A matrix can be created in MATLAB as follows (note the
   commas AND semicolons):

» matrix = [1 , 2 , 3 ; 4 , 5 ,6 ; 7 , 8 , 9]

matrix =

   1   2    3
   4   5    6
   7   8    9
Extracting a Sub-Matrix
                            29

A portion of a matrix can be extracted and stored in a
smaller matrix by specifying the names of both matrices
and the rows and columns to extract. The syntax is:

   sub_matrix = matrix ( r1 : r2 , c1 : c2 ) ;

where r1 and r2 specify the beginning and ending rows
and c1 and c2 specify the beginning and ending columns
to be extracted to make the new matrix.
MATLAB Matrices
                               30

   A column vector can be           Here we extract column 2
   extracted from a matrix.         of the matrix and make a
   As an example we create a        column vector:
   matrix below:

» matrix=[1,2,3;4,5,6;7,8,9]    » col_two=matrix( : , 2)

matrix =                        col_two =
  1 2 3
  4 5 6                             2
  7 8 9                             5
                                    8
MATLAB Matrices
                               31

  A row vector can be               Here we extract row 2 of
  extracted from a matrix.          the matrix and make a
  As an example we create           row vector. Note that
  a matrix below:                   the 2:2 specifies the
                                    second row and the 1:3
» matrix=[1,2,3;4,5,6;7,8,9]        specifies which columns
                                    of the row.

matrix =
                                » rowvec=matrix(2 : 2 , 1 :
                                   3)
  1   2    3
  4   5    6                    rowvec =
  7   8    9
                                    4   5   6
Topics..
                            32

What is MATLAB ??
Basic Matrix Operations
Script Files /M-files and Function Files
Some more Operations and Functions
Plotting functions ..
Use of M-File
                          33

There are two kinds of M-files:
     Scripts, which do not accept input
     arguments or return output arguments. They
     operate on data in the workspace.
     Functions, which can accept input
     arguments and return output arguments.
     Internal variables are local to the function.


                        Click to create
                        a new M-File
M-File as script file
                                  34

                                 Save file as filename.m




                                                             Type what you want to
                                                             do, eg. Create matrices




                                                     If you include “;” at the
                                                     end of each statement,
                                                     result will not be shown
                                                     immediately




Run the file by typing the filename in the command window
MATLAB Function File
                                 35

function [a b c] = myfun(x, y)        Write these two lines to a file myfun.m
b = x * y; a = 100; c = x.^2;         and save it on MATLAB’s path

>> myfun(2,3)            % called with zero outputs
ans =
   100
>> u = myfun(2,3)        % called with one output
u =
   100
>> [u v w] = myfun(2,3) % called with all outputs
u =
   100
v =                  Any return value which is not stored in
     6               an output variable is simply discarded
w =
     4
Topics..
                         36

What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
Plotting functions ..
Some Useful MATLAB commands
                        37



who         List known variables
whos        List known variables plus their size
help        >> help sqrt     Help on using sqrt
lookfor     >> lookfor sqrt Search for
                   keyword sqrt in m-files
what        >> what a: List MATLAB files in a:
clear       Clear all variables from work space
clear x y   Clear variables x and y from work space
clc         Clear the command window
Some Useful MATLAB commands
                        38

what          List all m-files in current directory
dir           List all files in current directory
ls            Same as dir
type test     Display test.m in command window
delete test   Delete test.m
cd a:         Change directory to a:
chdir a:      Same as cd
pwd           Show current directory
which test    Display directory path to ‘closest’
test.m
MATLAB Logical Functions
                            39

    MATLAB also supports some logical functions.
xor (exclusive or)         Ex: xor (a, b)
   Where a and b are logical expressions. The xor
    operator evaluates to true if and only if one
    expression is true and the other is false. True is
    returned as 1, false as 0.
any (x)         returns 1 if any element of x is nonzero
all (x)         returns 1 if all elements of x are nonzero
isnan (x)       returns 1 at each NaN in x
isinf (x)       returns 1 at each infinity in x
finite (x)      returns 1 at each finite value in x
Matlab Selection Structures
                           40


An if - elseif - else structure in MATLAB.
Note that elseif is one word.

if   expression1        % is true
     % execute these commands
elseif expression2      % is true
     % execute these commands
else              % the default
     % execute these commands
end
MATLAB Repetition Structures
                             41



A for loop in MATLAB              for x = array
    for ind = 1:100
        b(ind)=sin(ind/10)
     end

while loop in MATLAB      while expression
   while x <= 10
        % execute these commands
    end
42



x=0.1:0.1:10;
b=sin(x);
Plot(b,x)
------ no
computational
complexity
Scalar - Matrix Addition
                             43

» a=3;
» b=[1, 2, 3;4, 5, 6]
b=
   1 2 3
   4 5 6
» c= b+a         % Add a to each element of b
c=
   4 5 6
   7 8 9
Scalar - Matrix Subtraction
                           44



» a=3;
» b=[1, 2, 3;4, 5, 6]
b=
   1 2 3
   4 5 6
» c = b - a %Subtract a from each element of b
c=
  -2 -1 0
   1 2 3
Scalar - Matrix Multiplication
                             45



» a=3;
» b=[1, 2, 3; 4, 5, 6]
b=
   1 2 3
   4 5 6
» c = a * b % Multiply each element of b by a
c=
   3 6 9
  12 15 18
Scalar - Matrix Division
                            46



» a=3;
» b=[1, 2, 3; 4, 5, 6]
b=
   1 2 3
   4 5 6
» c = b / a % Divide each element of b by a
c=
  0.3333 0.6667 1.0000
  1.3333 1.6667 2.0000
The use of “.” – “Element” Operation
                                 47



                     Given A:



Divide each element of      Multiply each       Square each
A by 2                      element of A by 3   element of A
MATLAB Toolboxes
                             48



MATLAB has a number of add-on software modules, called
toolbox , that perform more specialized computations.

  Signal Processing
  Image Processing
  Communications
  System Identification
  Wavelet Filter Design
  Control System
  Fuzzy Logic
  Robust Control
   -Analysis and Synthesis
  LMI Control
  Model Predictive Control
  …
MATLAB Demo
                           49


Demonstrations are invaluable since they give an indication
of the MATLAB capabilities.



A comprehensive set are available by typing the command
>>demo in MATLAB prompt.
   demo
An Interesting, MATLAB command
                    50




why

In case you ever needed a reason
Topics..
                         51

What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
Plotting functions ..
Plot
                                  52


                                        Example
PLOT Linear plot.
                                        x = [-3 -2 -1 0 1 2 3];
  PLOT(X,Y) plots vector Y              y1 = (x.^2) -1;
  versus vector X
                                        plot(x, y1,'bo-.');
  PLOT(Y) plots the columns of
  Y versus their index
  PLOT(X,Y,S) with plot
  symbols and colors
  See also SEMILOGX,
  SEMILOGY, TITLE,
  XLABEL, YLABEL, AXIS,
  AXES, HOLD, COLORDEF,
  LEGEND, SUBPLOT...




            52
Plot Properties
                              53

                                   Example

XLABEL X-axis label.               ...
                                   xlabel('x values');
   XLABEL('text') adds text        ylabel('y values');
  beside the X-axis on the
  current axis.


YLABEL Y-axis label.
  YLABEL('text') adds text
  beside the Y-axis on the
  current axis.




         53
Hold
                                    54

                                         Example
HOLD Hold current graph.                 ...
                                         hold on;
  HOLD ON holds the current
                                         y2 = x + 2;
  plot and all axis properties so
                                         plot(x, y2, 'g+:');
  that subsequent graphing
  commands add to the existing
  graph.
  HOLD OFF returns to the
  default mode
  HOLD, by itself, toggles the
  hold state.




          54
Subplot
                                    55


SUBPLOT Create axes in tiled
  positions.
  SUBPLOT(m,n,p), or
  SUBPLOT(mnp), breaks the Figure
  window into an m-by-n matrix of
  small axes
 Example
 x = [-3 -2 -1 0 1 2 3];
 y1 = (x.^2) -1;
 % Plot y1 on the top
 subplot(2,1,1);
 plot(x, y1,'bo-.');
 xlabel('x values');
 ylabel('y values');
 % Plot y2 on the bottom
 subplot(2,1,2);
 y2 = x + 2;
 plot(x, y2, 'g+:');

             55
Figure
                                   56



  FIGURE Create figure window.
    FIGURE, by itself, creates a
    new figure window, and
    returns its handle.

Example
x = [-3 -2 -1 0 1 2 3];
y1 = (x.^2) -1;
% Plot y1 in the 1st Figure
plot(x, y1,'bo-.');
xlabel('x values');
ylabel('y values');
% Plot y2 in the 2nd Figure
figure
y2 = x + 2;
plot(x, y2, 'g+:');
            56
Surface Plot
                            57

x = 0:0.1:2;
y = 0:0.1:2;
[xx, yy] = meshgrid(x,y);
zz=sin(xx.^2+yy.^2);
surf(xx,yy,zz)
xlabel('X axes')
ylabel('Y axes')




          57
3 D Surface Plot
                        58


contourf-colorbar-plot3-waterfall-contour3-mesh-surf




     58
MATLAB Applications
                           59

 DSP
>> t=-2*pi:0.1:2*pi;
y=1.5*sin(t);
plot(t,y);
xlabel('------> time')
ylabel('------> sin(t)')




            59
MATLAB Applications
                           60


 DSP
>> t=-2*pi:0.1:2*pi;
y=1.5*cos(t);
stem(t,y);
xlabel('------> time')
ylabel('------> sin(t)')




            60
MATLAB Applications
                           61

DSP
 n=input('enter value of n')
 t=0:1:n-1;
 y1=ones(1,n); %unit step
 y2=[zeros(1,4) ones(1,n-4)]; %delayed unit step
 subplot(2,1,1);
 stem(t,y1,'filled');ylabel('amplitude');
 xlabel('n----->');ylabel('amplitude');
 subplot(2,1,2);
 stem(t,y2,'filled');
 xlabel('n----->');ylabel('amplitude');
          61
MATLAB Applications
                   62

DSP




      62
MATLAB Applications
                                          63

Control Systems
Transfer Function

          p1 s n + p 2 s n −1 + ... + p n +1
 H (s ) =
          q1 s m + q1 s m −1 + ... + q m +1


 where
  p1 , p 2 ... p n +1   numerator coefficients
  q1 , q1 ... q m +1    denominator coefficients

                   63
MATLAB Applications
                            64

Control Systems
Transfer Function
 Consider a linear time invariant (LTI) single-
 input/single-output system

               y ''+ 6 y '+ 5 y = 4u '+ 3u
 Applying Laplace Transform to both sides with
 zero initial conditions
                        Y ( s)     4s + 3
               G ( s) =        = 2
                        U ( s) s + 6s + 5
          64
MATLAB Applications
                       65

Control Systems
Transfer Function
>> num = [4 3];             >> [num,den] =
>> den = [1 6 5];                tfdata(sys,'v')
>> sys = tf(num,den)        num =
  Transfer function:            0 4 3
    4s+3                    den =
  -----------------             1 6 5
  s^2 + 6 s + 5

          65
MATLAB Applications
                                     66

Control Systems
Zero-pole-gain model (ZPK)
           (s − p1)(s − p2 ) +... + (s − pn )
H (s ) = K
           (s −q1)(s −q2 ) +... + (s −qm )


where
p1 , p2 ... pn+1        the zeros of H(s)
 q1,q1 ... qm+1         the poles of H(s)
                   66
MATLAB Applications
                            67

Control Systems
Zero-pole-gain model (ZPK)
    Consider a Linear time invariant (LTI) single-
    input/single-output system
               y ''+ 6 y '+ 5 y = 4u '+ 3u
    Applying Laplace Transform to both sides with
    zero initial conditions

             Y (s)      4s + 3    4( s + 0.75)
     G (s) =        = 2         =
             U ( s ) s + 6 s + 5 ( s + 1)( s + 5)
          67
MATLAB Applications
                                       68

Control Systems
 >> G=tf([4 3],[1 6 5]) >> [z,p,k]=zpkdata(G)

 Transfer function:    z=
   4s+3                  [-0.7500]
 -------------
 s^2 + 6 s + 5         p=
                        [-5;-1]

                       k=
                            4




                68
MATLAB Applications
                      69

Control Systems
>> bode(G)




         69
MATLAB Applications
                       70

Control Systems
>> rlocus(G)




          70
MATLAB Applications
                        71

Control Systems
>> nyquist(G)




          71
MATLAB Applications
                      72

Control Systems
>> step(G)




         72
MATLAB Applications
                      73

Control Systems
>> impulse(G)




         73
MATLAB Applications
                               74

Communication
>> t=0:pi/100:2*pi;
>> x=sin(t);
>> subplot(211);plot(t,x);
>> Fc=1000;
>> Fs=2000;
>> y=ammod(x,Fc,Fs);
>> subplot(212);plot(t,y);




                 74
MATLAB Applications
                    75

Communication




       75
Online MATLAB Resources
                       76


www.mathworks.com/
www.mathtools.net/MATLAB
www.math.utah.edu/lab/ms/matlab/matlab.html
web.mit.edu/afs/athena.mit.edu/software/matlab/
 www/home.html
www.utexas.edu/its/rc/tutorials/matlab/
www.math.ufl.edu/help/matlab-tutorial/
www.indiana.edu/~statmath/math/matlab/links.html
www-h.eng.cam.ac.uk/help/tpl/programs/matlab.html
       76
Reference Books
                           77




Mastering MATLAB 7, D. Hanselman and B. Littlefield,
Prentice Hall, 2004

Getting Started with MATLAB 7: A Quick Introduction
for Scientists and Engineers, R. Pratap, Oxford University
Press, 2005.




          77
Some More Web Resources
                          78

 MATLAB Educational sites:
http://www.eece.maine.edu/mm/matweb.html


 Yahoo! MATLAB Web site:
dir.yahoo.com/Science/mathematics/software/matlab/


 Newsgroup:
 comp.soft-sys.matlab


           78
Thanks
     79




Questions ??

Mais conteúdo relacionado

Mais procurados

Conditional Control in MATLAB Scripts
Conditional Control in MATLAB ScriptsConditional Control in MATLAB Scripts
Conditional Control in MATLAB ScriptsShameer Ahmed Koya
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabTarun Gehlot
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabBilawalBaloch1
 
MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3reddyprasad reddyvari
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlabaman gupta
 
Sparse matrix
Sparse matrixSparse matrix
Sparse matrixdincyjain
 
Ddl &amp; dml commands
Ddl &amp; dml commandsDdl &amp; dml commands
Ddl &amp; dml commandsAnjaliJain167
 
Optimal binary search tree
Optimal binary search treeOptimal binary search tree
Optimal binary search treeKavya P
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
Matlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IMatlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IVijay Kumar Gupta
 
Master Data Management – Das allwissende System? Analyse aus einer strategisc...
Master Data Management – Das allwissende System? Analyse aus einer strategisc...Master Data Management – Das allwissende System? Analyse aus einer strategisc...
Master Data Management – Das allwissende System? Analyse aus einer strategisc...Maxim Munvez
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab Arshit Rai
 
Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Deepam Aggarwal
 

Mais procurados (20)

Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Conditional Control in MATLAB Scripts
Conditional Control in MATLAB ScriptsConditional Control in MATLAB Scripts
Conditional Control in MATLAB Scripts
 
Matlab Workshop Presentation
Matlab Workshop PresentationMatlab Workshop Presentation
Matlab Workshop Presentation
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Sparse matrix
Sparse matrixSparse matrix
Sparse matrix
 
Ddl &amp; dml commands
Ddl &amp; dml commandsDdl &amp; dml commands
Ddl &amp; dml commands
 
Optimal binary search tree
Optimal binary search treeOptimal binary search tree
Optimal binary search tree
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Matlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IMatlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - I
 
Master Data Management – Das allwissende System? Analyse aus einer strategisc...
Master Data Management – Das allwissende System? Analyse aus einer strategisc...Master Data Management – Das allwissende System? Analyse aus einer strategisc...
Master Data Management – Das allwissende System? Analyse aus einer strategisc...
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 
All About MATLAB
All About MATLABAll About MATLAB
All About MATLAB
 
Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause
 

Destaque

Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsRay Phan
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to MatlabAmr Rashed
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introductionideas2ignite
 
MATLAB Modeling of SPT and Grain Size Data in Producing Soil Profile
MATLAB Modeling of SPT and Grain Size Data in Producing Soil ProfileMATLAB Modeling of SPT and Grain Size Data in Producing Soil Profile
MATLAB Modeling of SPT and Grain Size Data in Producing Soil ProfilePsychōjit MØmz
 
Matlab Mech Eee Lectures 1
Matlab Mech Eee Lectures 1Matlab Mech Eee Lectures 1
Matlab Mech Eee Lectures 1Ayyarao T S L V
 
An introduction to FACTS
An introduction to FACTSAn introduction to FACTS
An introduction to FACTSAyyarao T S L V
 
Power Flow in a Transmission line
Power Flow in a Transmission linePower Flow in a Transmission line
Power Flow in a Transmission lineAyyarao T S L V
 
Matlab Mech Eee Lectures 1
Matlab Mech Eee Lectures 1Matlab Mech Eee Lectures 1
Matlab Mech Eee Lectures 1Ayyarao T S L V
 
Static shunt compensation
Static shunt compensationStatic shunt compensation
Static shunt compensationAyyarao T S L V
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to MatlabTariq kanher
 
An introduction to FACTS Technology
An introduction to FACTS TechnologyAn introduction to FACTS Technology
An introduction to FACTS TechnologyAyyarao T S L V
 
Simulink - Introduction with Practical Example
Simulink - Introduction with Practical ExampleSimulink - Introduction with Practical Example
Simulink - Introduction with Practical ExampleKamran Gillani
 
Matlab for Electrical Engineers
Matlab for Electrical EngineersMatlab for Electrical Engineers
Matlab for Electrical EngineersManish Joshi
 
Objectives of shunt compensation
Objectives of shunt compensationObjectives of shunt compensation
Objectives of shunt compensationAyyarao T S L V
 
Basic types of facts controllers
Basic types of facts controllersBasic types of facts controllers
Basic types of facts controllersAyyarao T S L V
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABRavikiran A
 

Destaque (20)

MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
 
Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & Scientists
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
MATLAB Modeling of SPT and Grain Size Data in Producing Soil Profile
MATLAB Modeling of SPT and Grain Size Data in Producing Soil ProfileMATLAB Modeling of SPT and Grain Size Data in Producing Soil Profile
MATLAB Modeling of SPT and Grain Size Data in Producing Soil Profile
 
Matlab Mech Eee Lectures 1
Matlab Mech Eee Lectures 1Matlab Mech Eee Lectures 1
Matlab Mech Eee Lectures 1
 
An introduction to FACTS
An introduction to FACTSAn introduction to FACTS
An introduction to FACTS
 
Power Flow in a Transmission line
Power Flow in a Transmission linePower Flow in a Transmission line
Power Flow in a Transmission line
 
Matlab Mech Eee Lectures 1
Matlab Mech Eee Lectures 1Matlab Mech Eee Lectures 1
Matlab Mech Eee Lectures 1
 
Static shunt compensation
Static shunt compensationStatic shunt compensation
Static shunt compensation
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to Matlab
 
Ballas1
Ballas1Ballas1
Ballas1
 
An introduction to FACTS Technology
An introduction to FACTS TechnologyAn introduction to FACTS Technology
An introduction to FACTS Technology
 
Simulink - Introduction with Practical Example
Simulink - Introduction with Practical ExampleSimulink - Introduction with Practical Example
Simulink - Introduction with Practical Example
 
Matlab for Electrical Engineers
Matlab for Electrical EngineersMatlab for Electrical Engineers
Matlab for Electrical Engineers
 
Objectives of shunt compensation
Objectives of shunt compensationObjectives of shunt compensation
Objectives of shunt compensation
 
Basic types of facts controllers
Basic types of facts controllersBasic types of facts controllers
Basic types of facts controllers
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 

Semelhante a Matlab

MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxprashantkumarchinama
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondMahuaPal6
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionAmeen San
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systemsRaghav Shetty
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsMukesh Kumar
 
matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxlekhacce
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Randa Elanwar
 

Semelhante a Matlab (20)

Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab summary
Matlab summaryMatlab summary
Matlab summary
 
Matlab tut2
Matlab tut2Matlab tut2
Matlab tut2
 
EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
 
Matlab guide
Matlab guideMatlab guide
Matlab guide
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systems
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsx
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
An Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked ExamplesAn Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked Examples
 

Último

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 

Último (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Matlab

  • 1. 1 C Language is Simplest.
  • 2. 2 What may be the size of the program for writing a C code that generates sin wave?
  • 3. 3 But we can do the same by only three lines.
  • 4. x=0.1:0.1:10; 4 b=sin(x); Plot(x,b) ------ no computational complexity
  • 5. 5 That is the beauty we have as an engineer. Name is MATLAB
  • 6. Recent Trends in Computational techniques for Engineering 6 Use of MATLAB in Engineering Prof. Ashish M. Kothari Department of Electronics & Communication Engineering Atmiya Institute of Technology & Science, Rajkot
  • 7. Topics.. 7 What is MATLAB ?? Basic Matrix Operations Script Files and M-files Some more Operations and Functions Plotting functions ..
  • 8. Topics.. 8 What is MATLAB ?? Basic Matrix Operations Script Files and M-files Some more Operations and Functions Plotting functions
  • 9. MATLAB 9 “MATrix LABoratory” Powerful, extensible, highly integrated computation, programming, visualization, and simulation package Widely used in engineering, mathematics, and science
  • 10. MATLAB 10 Everything in MATLAB is a matrix !
  • 11. MATLAB- Starting & Quiting 11 Starting MATLAB On a Microsoft Windows platform, to start MATLAB, double-click the MATLAB shortcut icon on your Windows desktop. On Linux, to start MATLAB, type matlab at the operating system prompt. After starting MATLAB, the MATLAB desktop opens – see “MATLAB Desktop”. You can change the directory in which MATLAB starts, define startup options including running a script upon startup, and reduce startup time in some situations.
  • 12. MATLAB- Starting & Quiting 12 Quiting MATLAB To end your MATLAB session, select Exit MATLAB from the File menu in the desktop, or type quit in the Command Window.
  • 14.
  • 15. MATLAB Variable 15 Variable names ARE case sensitive Variable names can contain up to 63 characters (as of MATLAB 6.5 and newer) Variable names must start with a letter followed by letters, digits, and underscores.
  • 16. MATLAB Variable 16 >> 16 + 24 no declarations needed ans = 40 >> product = 16 * 23.24 mixed data types product = 371.84 semi-colon suppresses output of >> product = 16 *555.24; the calculation’s result >> product product = 8883.8
  • 17. MATLAB Variable 17 >> clear clear removes all variables; >> product = 2 * 3^3; >> comp_sum = (2 + 3i) + (2 - 3i); clear x y removes only x and y >> show_i = i^2; complex numbers (i or j) require >> save three_things no special handling >> clear >> load three_things >> who save/load are used to Your variables are: comp_sum product show_i retain/restore workspace variables >> product product = 54 use home to clear screen and put >> show_i cursor at the top of the screen show_i = -1
  • 18. MATLAB Special Variables 18 ans Default variable name for results pi Value of π eps Smallest incremental number inf Infinity NaN Not a number e.g. 0/0 i and j i = j = square root of -1 realmin The smallest usable positive real number realmax The largest usable positive real number
  • 19. Topics.. 19 What is MATLAB ?? Basic Matrix Operations Script Files and M-files Some more Operations and Functions Plotting functions ..
  • 20. Math & Assignment Operators 20 Power ^ or .^ e.g a^b or a.^b Multiplication * or .* e.g a*b or a.*b Division / or ./ e.g a/b or a./b or or . e.g ba or b.a NOTE: 56/8 = 856 - (unary) + (unary) Addition + a+b Subtraction - a-b Assignment = a=b (assign b to a)
  • 21. Other MATLAB symbols 21 >> prompt ... continue statement on next line , separate statements and data % start comment which ends at end of line ; (1) suppress output (2) used as a row separator in a matrix : specify range
  • 22. MATLAB Relational Operators 22 MATLAB supports six relational operators. Less Than < Less Than or Equal <= Greater Than > Greater Than or Equal >= Equal To == Not Equal To ~=
  • 23. MATLAB Logical Operators 23 MATLAB supports three logical operators. not ~ % highest precedence and & % equal precedence with or or | % equal precedence with and
  • 24. MATLAB Matrices 24 MATLAB treats all variables as matrices. For our purposes a matrix can be thought of as an array, in fact, that is how it is stored. Vectors are special forms of matrices and contain only one row OR one column. Scalars are matrices with only one row AND one column
  • 25. MATLAB Matrices 25 A matrix with only one row AND one column is a scalar. A scalar can be created in MATLAB as follows: » a_value=23 a_value = 23
  • 26. MATLAB Matrices 26 A matrix with only one row is called a row vector. A row vector can be created in MATLAB as follows (note the commas): » rowvec = [12 , 14 , 63] rowvec = 12 14 63
  • 27. MATLAB Matrices 27 A matrix with only one column is called a column vector. A column vector can be created in MATLAB as follows (note the semicolons): » colvec = [13 ; 45 ; -2] colvec = 13 45 -2
  • 28. MATLAB Matrices 28 A matrix can be created in MATLAB as follows (note the commas AND semicolons): » matrix = [1 , 2 , 3 ; 4 , 5 ,6 ; 7 , 8 , 9] matrix = 1 2 3 4 5 6 7 8 9
  • 29. Extracting a Sub-Matrix 29 A portion of a matrix can be extracted and stored in a smaller matrix by specifying the names of both matrices and the rows and columns to extract. The syntax is: sub_matrix = matrix ( r1 : r2 , c1 : c2 ) ; where r1 and r2 specify the beginning and ending rows and c1 and c2 specify the beginning and ending columns to be extracted to make the new matrix.
  • 30. MATLAB Matrices 30 A column vector can be Here we extract column 2 extracted from a matrix. of the matrix and make a As an example we create a column vector: matrix below: » matrix=[1,2,3;4,5,6;7,8,9] » col_two=matrix( : , 2) matrix = col_two = 1 2 3 4 5 6 2 7 8 9 5 8
  • 31. MATLAB Matrices 31 A row vector can be Here we extract row 2 of extracted from a matrix. the matrix and make a As an example we create row vector. Note that a matrix below: the 2:2 specifies the second row and the 1:3 » matrix=[1,2,3;4,5,6;7,8,9] specifies which columns of the row. matrix = » rowvec=matrix(2 : 2 , 1 : 3) 1 2 3 4 5 6 rowvec = 7 8 9 4 5 6
  • 32. Topics.. 32 What is MATLAB ?? Basic Matrix Operations Script Files /M-files and Function Files Some more Operations and Functions Plotting functions ..
  • 33. Use of M-File 33 There are two kinds of M-files: Scripts, which do not accept input arguments or return output arguments. They operate on data in the workspace. Functions, which can accept input arguments and return output arguments. Internal variables are local to the function. Click to create a new M-File
  • 34. M-File as script file 34 Save file as filename.m Type what you want to do, eg. Create matrices If you include “;” at the end of each statement, result will not be shown immediately Run the file by typing the filename in the command window
  • 35. MATLAB Function File 35 function [a b c] = myfun(x, y) Write these two lines to a file myfun.m b = x * y; a = 100; c = x.^2; and save it on MATLAB’s path >> myfun(2,3) % called with zero outputs ans = 100 >> u = myfun(2,3) % called with one output u = 100 >> [u v w] = myfun(2,3) % called with all outputs u = 100 v = Any return value which is not stored in 6 an output variable is simply discarded w = 4
  • 36. Topics.. 36 What is MATLAB ?? Basic Matrix Operations Script Files and M-files Some more Operations and Functions Plotting functions ..
  • 37. Some Useful MATLAB commands 37 who List known variables whos List known variables plus their size help >> help sqrt Help on using sqrt lookfor >> lookfor sqrt Search for keyword sqrt in m-files what >> what a: List MATLAB files in a: clear Clear all variables from work space clear x y Clear variables x and y from work space clc Clear the command window
  • 38. Some Useful MATLAB commands 38 what List all m-files in current directory dir List all files in current directory ls Same as dir type test Display test.m in command window delete test Delete test.m cd a: Change directory to a: chdir a: Same as cd pwd Show current directory which test Display directory path to ‘closest’ test.m
  • 39. MATLAB Logical Functions 39 MATLAB also supports some logical functions. xor (exclusive or) Ex: xor (a, b) Where a and b are logical expressions. The xor operator evaluates to true if and only if one expression is true and the other is false. True is returned as 1, false as 0. any (x) returns 1 if any element of x is nonzero all (x) returns 1 if all elements of x are nonzero isnan (x) returns 1 at each NaN in x isinf (x) returns 1 at each infinity in x finite (x) returns 1 at each finite value in x
  • 40. Matlab Selection Structures 40 An if - elseif - else structure in MATLAB. Note that elseif is one word. if expression1 % is true % execute these commands elseif expression2 % is true % execute these commands else % the default % execute these commands end
  • 41. MATLAB Repetition Structures 41 A for loop in MATLAB for x = array for ind = 1:100 b(ind)=sin(ind/10) end while loop in MATLAB while expression while x <= 10 % execute these commands end
  • 43. Scalar - Matrix Addition 43 » a=3; » b=[1, 2, 3;4, 5, 6] b= 1 2 3 4 5 6 » c= b+a % Add a to each element of b c= 4 5 6 7 8 9
  • 44. Scalar - Matrix Subtraction 44 » a=3; » b=[1, 2, 3;4, 5, 6] b= 1 2 3 4 5 6 » c = b - a %Subtract a from each element of b c= -2 -1 0 1 2 3
  • 45. Scalar - Matrix Multiplication 45 » a=3; » b=[1, 2, 3; 4, 5, 6] b= 1 2 3 4 5 6 » c = a * b % Multiply each element of b by a c= 3 6 9 12 15 18
  • 46. Scalar - Matrix Division 46 » a=3; » b=[1, 2, 3; 4, 5, 6] b= 1 2 3 4 5 6 » c = b / a % Divide each element of b by a c= 0.3333 0.6667 1.0000 1.3333 1.6667 2.0000
  • 47. The use of “.” – “Element” Operation 47 Given A: Divide each element of Multiply each Square each A by 2 element of A by 3 element of A
  • 48. MATLAB Toolboxes 48 MATLAB has a number of add-on software modules, called toolbox , that perform more specialized computations. Signal Processing Image Processing Communications System Identification Wavelet Filter Design Control System Fuzzy Logic Robust Control -Analysis and Synthesis LMI Control Model Predictive Control …
  • 49. MATLAB Demo 49 Demonstrations are invaluable since they give an indication of the MATLAB capabilities. A comprehensive set are available by typing the command >>demo in MATLAB prompt. demo
  • 50. An Interesting, MATLAB command 50 why In case you ever needed a reason
  • 51. Topics.. 51 What is MATLAB ?? Basic Matrix Operations Script Files and M-files Some more Operations and Functions Plotting functions ..
  • 52. Plot 52 Example PLOT Linear plot. x = [-3 -2 -1 0 1 2 3]; PLOT(X,Y) plots vector Y y1 = (x.^2) -1; versus vector X plot(x, y1,'bo-.'); PLOT(Y) plots the columns of Y versus their index PLOT(X,Y,S) with plot symbols and colors See also SEMILOGX, SEMILOGY, TITLE, XLABEL, YLABEL, AXIS, AXES, HOLD, COLORDEF, LEGEND, SUBPLOT... 52
  • 53. Plot Properties 53 Example XLABEL X-axis label. ... xlabel('x values'); XLABEL('text') adds text ylabel('y values'); beside the X-axis on the current axis. YLABEL Y-axis label. YLABEL('text') adds text beside the Y-axis on the current axis. 53
  • 54. Hold 54 Example HOLD Hold current graph. ... hold on; HOLD ON holds the current y2 = x + 2; plot and all axis properties so plot(x, y2, 'g+:'); that subsequent graphing commands add to the existing graph. HOLD OFF returns to the default mode HOLD, by itself, toggles the hold state. 54
  • 55. Subplot 55 SUBPLOT Create axes in tiled positions. SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into an m-by-n matrix of small axes Example x = [-3 -2 -1 0 1 2 3]; y1 = (x.^2) -1; % Plot y1 on the top subplot(2,1,1); plot(x, y1,'bo-.'); xlabel('x values'); ylabel('y values'); % Plot y2 on the bottom subplot(2,1,2); y2 = x + 2; plot(x, y2, 'g+:'); 55
  • 56. Figure 56 FIGURE Create figure window. FIGURE, by itself, creates a new figure window, and returns its handle. Example x = [-3 -2 -1 0 1 2 3]; y1 = (x.^2) -1; % Plot y1 in the 1st Figure plot(x, y1,'bo-.'); xlabel('x values'); ylabel('y values'); % Plot y2 in the 2nd Figure figure y2 = x + 2; plot(x, y2, 'g+:'); 56
  • 57. Surface Plot 57 x = 0:0.1:2; y = 0:0.1:2; [xx, yy] = meshgrid(x,y); zz=sin(xx.^2+yy.^2); surf(xx,yy,zz) xlabel('X axes') ylabel('Y axes') 57
  • 58. 3 D Surface Plot 58 contourf-colorbar-plot3-waterfall-contour3-mesh-surf 58
  • 59. MATLAB Applications 59 DSP >> t=-2*pi:0.1:2*pi; y=1.5*sin(t); plot(t,y); xlabel('------> time') ylabel('------> sin(t)') 59
  • 60. MATLAB Applications 60 DSP >> t=-2*pi:0.1:2*pi; y=1.5*cos(t); stem(t,y); xlabel('------> time') ylabel('------> sin(t)') 60
  • 61. MATLAB Applications 61 DSP n=input('enter value of n') t=0:1:n-1; y1=ones(1,n); %unit step y2=[zeros(1,4) ones(1,n-4)]; %delayed unit step subplot(2,1,1); stem(t,y1,'filled');ylabel('amplitude'); xlabel('n----->');ylabel('amplitude'); subplot(2,1,2); stem(t,y2,'filled'); xlabel('n----->');ylabel('amplitude'); 61
  • 62. MATLAB Applications 62 DSP 62
  • 63. MATLAB Applications 63 Control Systems Transfer Function p1 s n + p 2 s n −1 + ... + p n +1 H (s ) = q1 s m + q1 s m −1 + ... + q m +1 where p1 , p 2 ... p n +1 numerator coefficients q1 , q1 ... q m +1 denominator coefficients 63
  • 64. MATLAB Applications 64 Control Systems Transfer Function Consider a linear time invariant (LTI) single- input/single-output system y ''+ 6 y '+ 5 y = 4u '+ 3u Applying Laplace Transform to both sides with zero initial conditions Y ( s) 4s + 3 G ( s) = = 2 U ( s) s + 6s + 5 64
  • 65. MATLAB Applications 65 Control Systems Transfer Function >> num = [4 3]; >> [num,den] = >> den = [1 6 5]; tfdata(sys,'v') >> sys = tf(num,den) num = Transfer function: 0 4 3 4s+3 den = ----------------- 1 6 5 s^2 + 6 s + 5 65
  • 66. MATLAB Applications 66 Control Systems Zero-pole-gain model (ZPK) (s − p1)(s − p2 ) +... + (s − pn ) H (s ) = K (s −q1)(s −q2 ) +... + (s −qm ) where p1 , p2 ... pn+1 the zeros of H(s) q1,q1 ... qm+1 the poles of H(s) 66
  • 67. MATLAB Applications 67 Control Systems Zero-pole-gain model (ZPK) Consider a Linear time invariant (LTI) single- input/single-output system y ''+ 6 y '+ 5 y = 4u '+ 3u Applying Laplace Transform to both sides with zero initial conditions Y (s) 4s + 3 4( s + 0.75) G (s) = = 2 = U ( s ) s + 6 s + 5 ( s + 1)( s + 5) 67
  • 68. MATLAB Applications 68 Control Systems >> G=tf([4 3],[1 6 5]) >> [z,p,k]=zpkdata(G) Transfer function: z= 4s+3 [-0.7500] ------------- s^2 + 6 s + 5 p= [-5;-1] k= 4 68
  • 69. MATLAB Applications 69 Control Systems >> bode(G) 69
  • 70. MATLAB Applications 70 Control Systems >> rlocus(G) 70
  • 71. MATLAB Applications 71 Control Systems >> nyquist(G) 71
  • 72. MATLAB Applications 72 Control Systems >> step(G) 72
  • 73. MATLAB Applications 73 Control Systems >> impulse(G) 73
  • 74. MATLAB Applications 74 Communication >> t=0:pi/100:2*pi; >> x=sin(t); >> subplot(211);plot(t,x); >> Fc=1000; >> Fs=2000; >> y=ammod(x,Fc,Fs); >> subplot(212);plot(t,y); 74
  • 75. MATLAB Applications 75 Communication 75
  • 76. Online MATLAB Resources 76 www.mathworks.com/ www.mathtools.net/MATLAB www.math.utah.edu/lab/ms/matlab/matlab.html web.mit.edu/afs/athena.mit.edu/software/matlab/ www/home.html www.utexas.edu/its/rc/tutorials/matlab/ www.math.ufl.edu/help/matlab-tutorial/ www.indiana.edu/~statmath/math/matlab/links.html www-h.eng.cam.ac.uk/help/tpl/programs/matlab.html 76
  • 77. Reference Books 77 Mastering MATLAB 7, D. Hanselman and B. Littlefield, Prentice Hall, 2004 Getting Started with MATLAB 7: A Quick Introduction for Scientists and Engineers, R. Pratap, Oxford University Press, 2005. 77
  • 78. Some More Web Resources 78 MATLAB Educational sites: http://www.eece.maine.edu/mm/matweb.html Yahoo! MATLAB Web site: dir.yahoo.com/Science/mathematics/software/matlab/ Newsgroup: comp.soft-sys.matlab 78
  • 79. Thanks 79 Questions ??