Matlab Basic
MATLAB Product Family 2
3
Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit and press enter. 4
Some Basic Commands 5
Some Basic Commands (contd…) 6
7
8
9
Types of MATLAB Variables 10
Defining Scalars 11
Variable Definitions 12
Variable Definitions 13
Arithmetic Operators on Scalars 14 MATLAB utilizes the following arithmetic operators:
Variable Definition (Contd…….) 15
Variables in Workspace Type who to check the stored variables in workspace. 16
Variables in Workspace Type whos to check the stored variables in long form. 17
Complex numbers A complex number 3+2i in Matlab is entered in the following form 18
Complex numbers An exponential number 3x10 -2 in Matlab is entered in the following form 19
Exercise#1 Investigate the effect of following commands 20
Defining Vectors 21
Defining Row Vectors 22 To create a row vector A simply type in: A = [ ] A(5) A(2)
Defining Row Vectors 23 v = [ ] A(6:9) A(1:4)
Defining Column Vectors 24 To create a column vector B simply type in: B = [3; 5; 0; 0; 1; 4; 9; -1; 1] B =9x1 vector B(5) B(3)
Defining Column Vectors 25 B = [3; 5; 0; 0; 1; 4; 9; -1; 1] x1 vector B(7:9) B(2:5) B =
Arithmetic Operators (Arrays) 26
Exercise#2 27 Investigate the effect of the following commands: V=[ ] and w=[ ]
Exercise#3 28 Investigate the effect of the following commands. z=[1; 1; 0; 0]
Defining Matrices 29 A Matrix is a mxn array
Defining Matrices 30 To enter the matrix The most obvious ways are to type
Defining Matrices N = N(1,3) or N(9) N(4,3) or N(12) N=[ ; ; ; ]
Defining Matrices N = N(1:4) N(10:12) N=[ ; ; ; ]
Defining Matrices N = N(1:2,1:2) N(3:4,3:4)
Defining Matrices N = N(:,1:2)
Defining Matrices N = N(3:4,:)
Exercise#4 36 Investigate the effect of the following commands: M=[1 2; 3 4]N=[-1 3; 5 2]
Exercise#5 37 Investigate the effect of the following commands: M=[1 2; 3 4]
Exercise#6 1) Define a matrix A of dimension 2 x 4 whose (i,j) entry is A(i,j)=i+j 2) Extract two 2 x 2 matrices A1 and A2 out of the matrix A. A1 contains the first two columns of A, A2 contains the last two columns of A 3) Compute the matrix B to be the sum of A1 and A2 4) Compute the eigen values and eigen vectors of B 5) Compute the determinant of B 6) Compute the inverse of B 7) Compute the rank of B
Defining Character Arrays (Strings) 39 Character arrays are created using single quote delimiter
Defining Character Arrays (Strings)
Conversion B/W Numeric & String Arrays To convert from numeric to string array –num2str To convert from string array to numeric array –str2num 41
Numeric to string conversion 42
String to Numeric conversion 43
QUESTIONS Thank you for your concentration 44