Page 34 - MATLAB an introduction with applications
P. 34
MATLAB Basics ——— 19
The basic computational unit in MATLAB is the matrix. A matrix expression is enclosed in square brackets,
[ ]. Blanks or commas separate the column elements, and semicolons or carriage returns separate the rows.
>>A = [1 2 3 4 ; 5 6 7 8 ; 9 10 11 12]
A =
1 2 3 4
5 6 7 8
9 10 11 12
The transpose of a simple matrix or a complex matrix is obtained by using the apostrophe key
>>B = A'
B =
1 5 9
2 6 10
3 7 11
4 8 12
Matrix multiplication is accomplished as follows:
>>C = A*B
C =
30 70 110
70 174 278
110 278 446
>>C = B*A
C =
107 122 137 152
122 140 158 176
137 158 179 200
152 176 200 224
The inverse of a matrix D is obtained as
>>D = [1 2 ; 3 4]
D =
1 2
3 4
>>E = inv (D)
E =
–2.0000 1.0000
1.5000 –0.5000
Similarly, its eigenvalue is
>> eig (D)
ans =
–0.3723
5.3723
Matrix operations require that the matrix dimensions be compatible. If A is an n × m and B is a p × r, then
A ± B is allowed only if n = p and m = r. Similarly, matrix product A * B is allowed only if m = p.
F:\Final Book\Sanjay\IIIrd Printout\Dt. 10-03-09