MATLAB Technical Computing Environment

Download Report

Transcript MATLAB Technical Computing Environment

MATLAB
Matrix Manipulation and
graphics
Matrix Generation in MATLAB
11 22 33 44 66
A=
55 68 92 35 47
68
B=
43 46 56 38 97
59
37
69 91 46 73 27
24
66
55 68 92
C = 43 46 56
D=
69 91 46
47
97
27
A = [4 3 4; 4 6 8; 3 6 6]
B = [35; 22 ; 40]
E = 55 68 92 35 47
68 66
G=
55 68 92 35 47
F=
57 70 94 37 49
59 47
37 97
24 27
C = A(2:4,1:3)
D = A(:,end)
E = A(2, :)
F = [ E ; E+2 ]
G = [B D]
Colon Notation
[Starting Point : Step : Ending Point]
A = [1 2 3 4 5 6 7]
A = [1:7]
B = [1 3 5 7 9 11 13]
B = [1:2:13]
C = [10 9 8 7 6 5]
C = [10: -1 : 5]
Common Matrices in MATLAB





ones(3,4) : All ones (3x4)
zeros(2) : All zeroes (2x2)
eye(3) : Identity (3x3)
rand(4,5) : Random numbers between 0
and 1 (4x5)
magic(4) : Dührer’s matrix (4x4)
Array and Matrix Operations






A’: Transpose of Matrix A
inv(A): Inverse of Matrix A
det(A): Determinant of Matrix A
eig(A): Eigenvalues of Matrix A
A.*A : “.” denotes element by element (array) multiplication of A
by B. Same approach can be used for element by element
division and exponention.
CAUTION: To do a matrix multiplication A*B, the number of
columns in A must be equal to the number of rows in B
To do an array multiplication both matrices must have the same
number of rows AND columns
Size of a Matrix or an Array
Solution of Linear Equations
Simple Plots




Plot(x,y): plots x vs y
Plot(x1,y1,x2,y2) :Used to show multiple plots
in the same figure.
Subplot(rows,columns,number)
Other useful commands:
Hold
Grid
Title(‘ ‘)
axis([ , , , ])
Xlabel(‘ ‘)
ylabel(‘ ‘)
Type Help plot for details
