Download presentation
Presentation is loading. Please wait.
Published bySharyl Dorsey Modified over 9 years ago
1
Matlab Basic
2
MATLAB Product Family 2
3
3
4
Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit and press enter. 4
5
Some Basic Commands 5
6
Some Basic Commands (contd…) 6
7
7
8
8
9
9
10
Types of MATLAB Variables 10
11
Defining Scalars 11
12
Variable Definitions 12
13
Variable Definitions 13
14
Arithmetic Operators on Scalars 14 MATLAB utilizes the following arithmetic operators:
15
Variable Definition (Contd…….) 15
16
Variables in Workspace Type who to check the stored variables in workspace. 16
17
Variables in Workspace Type whos to check the stored variables in long form. 17
18
Complex numbers A complex number 3+2i in Matlab is entered in the following form 18
19
Complex numbers An exponential number 3x10 -2 in Matlab is entered in the following form 19
20
Exercise#1 Investigate the effect of following commands 20
21
Defining Vectors 21
22
Defining Row Vectors 22 To create a row vector A simply type in: A = [2 0 1 4 7 1 5 6 4] 1 23 4 56 7 89 A(5) A(2)
23
Defining Row Vectors 23 v = [2 0 1 4 7 1 5 6 4] 1 23 4 56 7 89 A(6:9) A(1:4)
24
Defining Column Vectors 24 To create a column vector B simply type in: B = [3; 5; 0; 0; 1; 4; 9; -1; 1] 1 1 9 9 4 4 1 1 0 0 0 0 5 5 3 3 1 2 3 4 5 6 7 8 9 B =9x1 vector B(5) B(3)
25
Defining Column Vectors 25 B = [3; 5; 0; 0; 1; 4; 9; -1; 1] 1 1 9 9 4 4 1 1 0 0 0 0 5 5 3 3 1 2 3 4 5 6 7 8 9 9x1 vector B(7:9) B(2:5) B =
26
Arithmetic Operators (Arrays) 26
27
Exercise#2 27 Investigate the effect of the following commands: V=[2 4 7 5] and w=[1 3 8 9]
28
Exercise#3 28 Investigate the effect of the following commands. z=[1; 1; 0; 0]
29
Defining Matrices 29 A Matrix is a mxn array
30
Defining Matrices 30 To enter the matrix The most obvious ways are to type
31
Defining Matrices 31 1 1 3 3 3 3 1 1 9 9 1 1 7 7 4 4 7 7 4 4 1 1 9 9 1 1 8 8 3 3 0 0 1 2 3 4 5 8 9 6 7 10 11 12 14 15 16 13 N = N(1,3) or N(9) N(4,3) or N(12) N=[1 3 9 1; 2 1 7 4; 7 4 1 8; 1 9 3 0]
32
Defining Matrices 32 1 1 3 3 3 3 1 1 9 9 1 1 7 7 4 4 7 7 4 4 1 1 9 9 1 1 8 8 3 3 0 0 1 2 3 4 5 8 9 6 7 10 11 12 14 15 16 13 N = N(1:4) N(10:12) N=[1 3 9 1; 2 1 7 4; 7 4 1 8; 1 9 3 0]
33
Defining Matrices 33 1 1 3 3 3 3 1 1 9 9 1 1 7 7 4 4 7 7 4 4 1 1 9 9 1 1 8 8 3 3 0 0 1 2 3 4 5 8 9 6 7 10 11 12 14 15 16 13 N = N(1:2,1:2) N(3:4,3:4)
34
Defining Matrices 34 1 1 3 3 3 3 1 1 9 9 1 1 7 7 4 4 7 7 4 4 1 1 9 9 1 1 8 8 3 3 0 0 1 2 3 4 5 8 9 6 7 10 11 12 14 15 16 13 N = N(:,1:2)
35
Defining Matrices 35 1 1 3 3 3 3 1 1 9 9 1 1 7 7 4 4 7 7 4 4 1 1 9 9 1 1 8 8 3 3 0 0 1 2 3 4 5 8 9 6 7 10 11 12 14 15 16 13 N = N(3:4,:)
36
Exercise#4 36 Investigate the effect of the following commands: M=[1 2; 3 4]N=[-1 3; 5 2]
37
Exercise#5 37 Investigate the effect of the following commands: M=[1 2; 3 4]
38
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
39
Defining Character Arrays (Strings) 39 Character arrays are created using single quote delimiter 1 2345 6
40
Defining Character Arrays (Strings) 40 1 2 345 6
41
Conversion B/W Numeric & String Arrays To convert from numeric to string array –num2str To convert from string array to numeric array –str2num 41
42
Numeric to string conversion 42
43
String to Numeric conversion 43
44
QUESTIONS Thank you for your concentration 44
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.