Saturday, January 31, 2009

Vectors and Matrices - 1

The Scilab is like Matlab (Matrix Lab), I don't like Matlab but it's other thing.

The Scilab was created for matrix manipulation, so it can operate matrices (and similars) naturally.

This is the first post about vectors and matrices.

Let's do something.

Get a vector
x = [1 2 3 4]' (x is a column vector)
and a matrix
A = [1 2 3 4;
1 2 3 4;
1 2 3 4;
1 2 3 4].

If y = A x (matrix multiplication), then y = [x[1]A[1,1]+x[2]A[2,1]+x[3]A[3,1]+x[4]A[4,1] x[1]A[1,2]+x[2]A[2,2]+x[3]A[3,2]+x[4]A[4,2] x[1]A[1,3]+x[2]A[2,3]+x[3]A[3,3]+x[4]A[4,3] x[1]A[1,4]+x[2]A[2,4]+x[3]A[3,4]+x[4]A[4,4]] = [1²+2²+3²+4² 1²+2²+3²+4² 1²+2²+3²+4² 1²+2²+3²+4²] = [30 30 30 30].

For who studies linear algebra, the equation y = A x is a generic linear system of 1st order.

Using Scilab, we can do the commands.

-->x = [1 2 3 4]'; // the apostrophe { ' } indicates the transposition, so x is a column vector because [1 2 3 4] is a line vector and x is [1 2 3 4] transpose.

-->A = [1 2 3 4;
-->1 2 3 4;
-->1 2 3 4;
-->1 2 3 4];

-->y = A*x
y =

30.
30.
30.
30.

Look that y is a column vector like x (with 4 lines), it's correct because A is a square matrix (with 4 lines and 4 columns) and x is a column vector (with 4 lines).

Using the rule dim(y) = dim(Ax) = [number of lines of A, (number of columns of A, number of lines of x), number of columns of x] = [number of lines of A, number of columns of x] (parenthesis out).

I'll do more posts about vectors and matrices. Wait and see.

No comments: