21
BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer ,Telecom Department University of Engineering & Technology Taxila

BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

Embed Size (px)

DESCRIPTION

MATLAB interactive session

Citation preview

Page 1: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

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…

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…

MATLAB interactive session

Page 4: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…
Page 5: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

VARIABLES

Page 6: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

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

Predefined constants

Page 8: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

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

SCALAR OPERATIONS

Page 10: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

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

The assignment operator

Page 12: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

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

Managing the work session

Page 14: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

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…

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…

COMPLEX NUMBER OPERATIONS

Page 17: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

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

Formatting commands

Page 19: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

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

FUNCTIONS

Page 21: BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology…

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