Tuesday, October 6, 2009

matlab basics : matrices

% 3 by 3 matrix

A = [ 2 1 1
1 -2 1
1 1 0]

A =

2 1 1
1 -2 1
1 1 0

% column vector

b = [10; 8; 3]

b =

10
8
3

% matrix multiplication

A * [1; 0; 0]

ans =

2
1
1


% index operations

A(1:3)

ans =

2 1 1

>> A(1:4)

ans =

2 1 1 1


% adding 3 columns to the A matrix and assigning result to B
B = [A(1:3) 1 0 0; A(4:6) 0 1 0; A(7:9) 0 0 1]

B =

2 1 1 1 0 0
1 -2 1 0 1 0
1 1 0 0 0 1



% the rref function for solving a linear system

rref(A)

No comments:

Post a Comment