» A=[2 -3 2; -4 2 -6; 2 2 4]The second input shows a standard trick for entering column vectors without too many keystrokes: enter the vector as a row vector, and the take its transpose.
A =
2 -3 2
-4 2 -6
2 2 4
» b=[5 14 8]'
b =
5
14
8
» A\b
ans =
1.0e+002 *
1.09000000000000
0.27000000000000
-0.66000000000000
Note that the answer is x1 = 109, x2 = 27, and x3 = -66, but Matlab frequently writes computed quantities in scientific notation.
Calculating inverses and determinants is straightforward:
» inv(A)Extracting a row and substituting a column (for instance) are easy operations if one takes advantage of Matlab's colon notation:
ans =
5.00000000000000 4.00000000000000 3.50000000000000
1.00000000000000 1.00000000000000 1.00000000000000
-3.00000000000000 -2.50000000000000 -2.00000000000000
» det(A)
ans =
4
» A(2,:)Matrix multiplication, transpose, and "applying a matrix to a vector" (which is also matrix multiplication) look like:
ans =
-4 2 -6
» AA=[A(:,1:2) b]
AA =
2 -3 5
-4 2 14
2 2 8
» A*AABut matrix multiplication must be done with matrices of the appropriate dimensions, and Matlab enforces it:
ans =
20 -8 -16
-28 4 -40
4 6 70
» A'
ans =
2 -4 2
-3 2 2
2 -6 4
» bb=b'
bb =
5 14 8
» A*b
ans =
-16
-40
70
» A*bbUseful commands include quick entry of larger identity and zero matrices, and augmenting one matrix by another:
??? Error using ==> *
Inner matrix dimensions must agree.
» eye(4,4)
ans =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
» zeros(2,3)
ans =
0 0 0
0 0 0
» M=[A eye(3,3)]
M =
2 -3 2 1 0 0
-4 2 -6 0 1 0
2 2 4 0 0 1