SlideShare a Scribd company logo
1 of 14
Mathematical Modeling and Simulation

       Introduction To MATLAB




           Prof. Muhammad Saeed
Basic Features
 MATLAB Windows
     1.     Command ( << )
     2.     Command History
     3.     Workspace
     4.     Current Directory
     5.     Editor
     6.     Profiler
     7.     Help

 Simple Math in Command Window
     1. Operators:    +, -, *, /, , ^
     2. Variables: ans, pi, inf, NaN, i, j, realmin, realmax,
        ……, user-defined
Mathematical Modeling and Simulation                            2
3. Precision: significant digits and formats
       a) ‘format short’, ‘format short e’and ‘format short g’
       b) ‘format long’, ‘format long e’,’ format long g’
       c) ‘format hex’
       d) ‘format bank’
       e) ‘format +’
       4. Complex numbers
            a)     ‘imag()’, ‘real()’, ‘abs()’ and ‘angle()’

          Display and Help
         1. ‘who’ , ‘whos’, clear, clear a*, clear –regexp, clc,
            disp, ver, version, diary, commands
         2. Comments in MATLAB (%)
         3. Ellipses ( … ) and ‘;’ at the end of commands
               4. Built-in Functions and Help using fx, start and
                      Help
Mathematical Modeling and Simulation                                3
Mathematical Modeling and Simulation   4
….. Arrays and Matrices




Mathematical Modeling and Simulation                             5
….. Arrays and Matrices




Mathematical Modeling and Simulation                             6
….. Arrays and Matrices




Mathematical Modeling and Simulation                             7
 Basic Matrix Functions
   1. rank(a)
   2. inv(A)
   3. Ay, solves set of linear equations, A is a matrix and y is
       a vector
   4. det(A)
   5. eig(A), [v d]=eig(A) calculates eigen values and eigen
       vectors
   6. trace(A)
   10. sp=sparse(A),
   11. full(sp)
   12. or(a,b)
   13. xor(a,b)



  Mathematical Modeling and Simulation                              8
 M-File Scripts

   1. Specific Functions used in M-Files:
      echo, disp, input, keyboard, pause, pause(n),
   waitforbuttonpress
   2. All functions and control statements of MATLAB can
      be used in script files.
   3. Extension is ‘m’ ( file.m )
   4. M-File directly runs on the command line ( >>) as simple
      statements do. It is evaluated in MATLAB workspace.




 Mathematical Modeling and Simulation                        9
 M-File Functions
 1. Function name must be identical to M-File name.
 2. Function start with ‘function’ keyword and ends with
    ‘end’ keyword
 3. 1st line in M-File must be the function declaration
 4. The ‘error’ and ‘warning’ functions in the M-File are
    like ‘sprintf ‘
 5. Script file called in a function is evaluated in function
    workspace
 6. Subfunctions are called from the 1st function’s body
 7. Help for subfunction can be displayed by
    >>helpwin func/subfunc
 8. Functions can have zero input or zero output arguments.
 9. Functions can be called with fewer input and output
    arguments than are specified in the function definition
    but not with more arguments than specified.
 Mathematical Modeling and Simulation                           10
……….. M-File Functions
10. Function arguments can be determined by two variables:
    nargin and nargout.
11. The first set of contiguous comment lines after the
function declaration are the help text for the function
12. The ‘return’ statement is not necessary.
13. Script file called in a function is evaluated in function WS
14. Unlimited number of input and output arguments by
    specifying ‘varargin’ as the last argument and
‘varargout’          for output arguments.
15. ‘pcode’ command compiles the function
16. Functions can be nested.
17. One-Line‘inline’ functions can be defined as in C
    (by #define)
18. Anonymous functions are defined by handles .
19. Handles of MATLAB functions can also be created
Mathematical Modeling and Simulation                           11
 Set Functions
     1. isequal(a, b), compares as a whole
     2. unique(a), removes duplications
     3. ismember(a,b), ismember(a,’xyz’), element by
     element
     4. union(a,b), must be rows or columns
     5. intersect(a,b)
     6. diff(a)

 Base Conversion Functions
  1. dec2bin(x), bin2dec(x)
  2. dec2hex(x), hex2dec(x)
  3. dec2base(x, base), base2dec(x, base)
 Precision Functions
   digits(n), vpa(pi), vpa(x, d), vpa(‘pi’)
   Mathematical Modeling and Simulation                12
 Data Analysis
   1. mean(a), for a 2D matrix each rows s mean will be
       calculated.
   2. mean(a,1), row values are averaged
   3. mean(a,2), column values are averaged
   4. median(a)
   4. std(a), standard deviation
   5. var(a), Variance
   5. cov(a), covariance
   6. corrcoef(a), correlation coefficient
   7. diff(a), rows are subtracted
   8. min(a)
   9. max(a)
   10. cumsum(a)
   11. cumprod(a)
 Mathematical Modeling and Simulation                     13
End

Mathematical Modeling and Simulation         14

More Related Content

What's hot

100 c interview questions answers
100 c interview questions answers100 c interview questions answers
100 c interview questions answers
Sareen Kumar
 
Matlab intro
Matlab introMatlab intro
Matlab intro
fvijayami
 

What's hot (20)

Ocs752 unit 4
Ocs752   unit 4Ocs752   unit 4
Ocs752 unit 4
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
 
Ocs752 unit 3
Ocs752   unit 3Ocs752   unit 3
Ocs752 unit 3
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Java Tutorial: Part 4 - Data and Calculations
Java Tutorial: Part 4 - Data and CalculationsJava Tutorial: Part 4 - Data and Calculations
Java Tutorial: Part 4 - Data and Calculations
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++
 
Ocs752 unit 1
Ocs752   unit 1Ocs752   unit 1
Ocs752 unit 1
 
100 c interview questions answers
100 c interview questions answers100 c interview questions answers
100 c interview questions answers
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++
 
Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
 
Function
FunctionFunction
Function
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
12. Exception Handling
12. Exception Handling 12. Exception Handling
12. Exception Handling
 
Network security CS6
Network security   CS6Network security   CS6
Network security CS6
 
Scilab for real dummies j.heikell - part3
Scilab for real dummies j.heikell - part3Scilab for real dummies j.heikell - part3
Scilab for real dummies j.heikell - part3
 

Similar to Matlab 1

Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
Kurmendra Singh
 

Similar to Matlab 1 (20)

Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
Matlab1
Matlab1Matlab1
Matlab1
 
Adobe
AdobeAdobe
Adobe
 
Dsp file
Dsp fileDsp file
Dsp file
 
Python Modules, Packages and Libraries
Python Modules, Packages and LibrariesPython Modules, Packages and Libraries
Python Modules, Packages and Libraries
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
 
Tutorial2
Tutorial2Tutorial2
Tutorial2
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Python Modules and Libraries
Python Modules and LibrariesPython Modules and Libraries
Python Modules and Libraries
 

Recently uploaded

Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
SaadHumayun7
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
ashishpaul799
 

Recently uploaded (20)

Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Mbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptxMbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptx
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 

Matlab 1

  • 1. Mathematical Modeling and Simulation Introduction To MATLAB Prof. Muhammad Saeed
  • 2. Basic Features  MATLAB Windows 1. Command ( << ) 2. Command History 3. Workspace 4. Current Directory 5. Editor 6. Profiler 7. Help  Simple Math in Command Window 1. Operators: +, -, *, /, , ^ 2. Variables: ans, pi, inf, NaN, i, j, realmin, realmax, ……, user-defined Mathematical Modeling and Simulation 2
  • 3. 3. Precision: significant digits and formats a) ‘format short’, ‘format short e’and ‘format short g’ b) ‘format long’, ‘format long e’,’ format long g’ c) ‘format hex’ d) ‘format bank’ e) ‘format +’ 4. Complex numbers a) ‘imag()’, ‘real()’, ‘abs()’ and ‘angle()’  Display and Help 1. ‘who’ , ‘whos’, clear, clear a*, clear –regexp, clc, disp, ver, version, diary, commands 2. Comments in MATLAB (%) 3. Ellipses ( … ) and ‘;’ at the end of commands 4. Built-in Functions and Help using fx, start and Help Mathematical Modeling and Simulation 3
  • 5. ….. Arrays and Matrices Mathematical Modeling and Simulation 5
  • 6. ….. Arrays and Matrices Mathematical Modeling and Simulation 6
  • 7. ….. Arrays and Matrices Mathematical Modeling and Simulation 7
  • 8.  Basic Matrix Functions 1. rank(a) 2. inv(A) 3. Ay, solves set of linear equations, A is a matrix and y is a vector 4. det(A) 5. eig(A), [v d]=eig(A) calculates eigen values and eigen vectors 6. trace(A) 10. sp=sparse(A), 11. full(sp) 12. or(a,b) 13. xor(a,b) Mathematical Modeling and Simulation 8
  • 9.  M-File Scripts 1. Specific Functions used in M-Files: echo, disp, input, keyboard, pause, pause(n), waitforbuttonpress 2. All functions and control statements of MATLAB can be used in script files. 3. Extension is ‘m’ ( file.m ) 4. M-File directly runs on the command line ( >>) as simple statements do. It is evaluated in MATLAB workspace. Mathematical Modeling and Simulation 9
  • 10.  M-File Functions 1. Function name must be identical to M-File name. 2. Function start with ‘function’ keyword and ends with ‘end’ keyword 3. 1st line in M-File must be the function declaration 4. The ‘error’ and ‘warning’ functions in the M-File are like ‘sprintf ‘ 5. Script file called in a function is evaluated in function workspace 6. Subfunctions are called from the 1st function’s body 7. Help for subfunction can be displayed by >>helpwin func/subfunc 8. Functions can have zero input or zero output arguments. 9. Functions can be called with fewer input and output arguments than are specified in the function definition but not with more arguments than specified. Mathematical Modeling and Simulation 10
  • 11. ……….. M-File Functions 10. Function arguments can be determined by two variables: nargin and nargout. 11. The first set of contiguous comment lines after the function declaration are the help text for the function 12. The ‘return’ statement is not necessary. 13. Script file called in a function is evaluated in function WS 14. Unlimited number of input and output arguments by specifying ‘varargin’ as the last argument and ‘varargout’ for output arguments. 15. ‘pcode’ command compiles the function 16. Functions can be nested. 17. One-Line‘inline’ functions can be defined as in C (by #define) 18. Anonymous functions are defined by handles . 19. Handles of MATLAB functions can also be created Mathematical Modeling and Simulation 11
  • 12.  Set Functions 1. isequal(a, b), compares as a whole 2. unique(a), removes duplications 3. ismember(a,b), ismember(a,’xyz’), element by element 4. union(a,b), must be rows or columns 5. intersect(a,b) 6. diff(a)  Base Conversion Functions 1. dec2bin(x), bin2dec(x) 2. dec2hex(x), hex2dec(x) 3. dec2base(x, base), base2dec(x, base)  Precision Functions digits(n), vpa(pi), vpa(x, d), vpa(‘pi’) Mathematical Modeling and Simulation 12
  • 13.  Data Analysis 1. mean(a), for a 2D matrix each rows s mean will be calculated. 2. mean(a,1), row values are averaged 3. mean(a,2), column values are averaged 4. median(a) 4. std(a), standard deviation 5. var(a), Variance 5. cov(a), covariance 6. corrcoef(a), correlation coefficient 7. diff(a), rows are subtracted 8. min(a) 9. max(a) 10. cumsum(a) 11. cumprod(a) Mathematical Modeling and Simulation 13

Editor's Notes

  1. Mathematical Modeling and Simulation MATLAB
  2. MATLAB Mathematical Modeling and Simulation
  3. MATLAB Mathematical Modeling and Simulation
  4. MATLAB Mathematical Modeling and Simulation
  5. MATLAB Mathematical Modeling and Simulation