basics of matlab engr.mian shahzad iqbal lecturer,telecom department university of engineering &...
DESCRIPTION
MATLAB interactive sessionTRANSCRIPT
![Page 1: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/1.jpg)
BASICS OF MATLAB
Engr.Mian Shahzad IqbalLecturer ,Telecom Department
University of Engineering & Technology Taxila
![Page 2: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/2.jpg)
In this presentation …•You will identify the different windows in the MATLAB desktop.
•You will learn some of the basics of programming in the MATLAB.
•You will learn to use MATLAB as an interactive calculator.
![Page 3: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/3.jpg)
MATLAB interactive session
![Page 4: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/4.jpg)
![Page 5: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/5.jpg)
VARIABLES
![Page 6: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/6.jpg)
•A Variable in MATLAB is a symbol used to contain a value.
•A scalar variable is a variable that contains a single number.
•A global variable is that variable which is available in the workspace.
•Local variable is that variable which is created by a function and is not available outside the function.
•A string variable is composed of text (alphanumeric characters).
•Logical variables are the variables containing the logical values.
![Page 7: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/7.jpg)
Predefined constants
![Page 8: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/8.jpg)
• The several predefined constants are listed in the table below
Command Description
ans Temporary variable containing the most recent answer.
eps Specifies the accuracy of floating point precision.
i,j The imaginary unit
Inf Infinity
pi The number 3.14
NaN Indicates an undefined numerical result
![Page 9: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/9.jpg)
SCALAR OPERATIONS
![Page 10: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/10.jpg)
• Different operations that MATLAB performs on the scalars are listed, in their order of precedence, in the table below
symbol Operation MATLAB form
^ Exponentiation ab a^b
* Multiplication ab a*b
/ Right division a/b a/b
\ Left division b/a a\b
+ Addition a + b a+b
- Subtraction a - b a-b
![Page 11: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/11.jpg)
The assignment operator
![Page 12: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/12.jpg)
• The = sign in MATLAB is called the assignment or replacement operator.
• It is used to assign the numerical values to different variables in MATLAB.
• The variable on the left-hand side of the = operator is replaced by the right-hand side.
• General rules of using the = operator.
![Page 13: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/13.jpg)
Managing the work session
![Page 14: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/14.jpg)
1. clcclears the command window
2. clearRemoves all variables from the memory.
3. clear var1 var2Removes the variables var1 and var2 from the
memory.4. exist (‘name’)
Determines if a file or variable exists having the name ‘name’. A 1 indicates that a variable exists and 0 indicates variable does not exists.
5. quitstops MATLAB.
6. whoList the variables currently in the memory.
7. whosList the current variables and sizes, and indicates if
they have the imaginary parts.
![Page 15: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/15.jpg)
8. :Generates an array having regularly spaced
elements.9. ,
separates elements of an array. separates several commands on the same line.
10. ;Suppresses screen printing. Denotes a new row in
an array.11. …
continues a line
12. Arrow and control keys.
13. Smart recall.
14. Tab completion.
![Page 16: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/16.jpg)
COMPLEX NUMBER OPERATIONS
![Page 17: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/17.jpg)
• MATLAB handels complex number algebra automatically.
• For example,c1= 1- 2i
is entered as followc1 = 1-2i
• Common errors
![Page 18: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/18.jpg)
Formatting commands
![Page 19: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/19.jpg)
•Table below gives many variants of the format command
Commands Description and example.format short Four decimal digits (the default); 13.6745.format long 16 digits; 17.27549865424597.format short e
Five digits (four decimals) plus exponent; 6.3792e+03.
format long e
16 digits(15 decimals) plus exponent; 6.379243784781294e-04.
format bank Two decimal digits; 126.73.format + Positive, negative or zero; +.format rat Rational approximations; 43/7.format compact Suppresses some line feeds.
format ------------- Resets to less compact display.
![Page 20: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/20.jpg)
FUNCTIONS
![Page 21: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…](https://reader035.vdocuments.net/reader035/viewer/2022070616/5a4d1bf57f8b9ab0599e7c79/html5/thumbnails/21.jpg)
The table below lists some of the built-in functions of the MATLAB
Function MATLAB syntaxex exp(x)
sqrt (x)ln x log(x)
log10x Log10(x)cos x cos(x)sin x sin(x)tan x tan(x)cos-1x acos(x)sin-1x asin(x)tan-1x atan(x)
x