You are on page 1of 3

A vector is in fact a matrix but only with one row or column.

We can define the vector either by inserting the


elements of the row:

-->V1=[1 2 3 4]

V1 =

1. 2. 3. 4.

-->

or by inserting the elements of the column using the “;” terminator:

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

V2 =

1.

2.

3.

4.

-->

Keep in mind that for Scilab there is no difference between a vector or a matrix. Only the dimension is
different between them, all variable are of type “Double”:
Image: Variable Browser in Scilab

Once you have defined a matrix if you want to change some of it’s values there are two options. First is to
rewrite the value that needs to be changed by pointing what row and column within the matrix is to be
changed:

-->A(2,3)=60

A =

1. 2. 3. 4.

5. 6. 60. 8.

-->

In this example we changed the value of the element from matrix A positioned in row 2 and column 3.
Previously this value was 6 and after that we redefined it to 60.

Vectors

Column vector: v=[0 ;1 ;2]

Row vector: v=[0 1 2]

Operations: w=u+v

Element: w(2) gives 2nd element

x=w(2) assigns that number to scalar x

Dimensions: size(v) will print out the number of rows and columns
in v

Vector length: norm(v)

Element-by-element multiplication: u.*v

Dot product: sum(u.*v)


Matrices

Example of 2x3 matrix: A=[1 2 3; 4 5 6]

Transpose: A’

Multiplication: A*B

Vector of column sums: v=sum(A,1)

Vector of row sums: v=sum(A,2)

Sum of all elements: sum(A)

Single column of a matrix: v=A(:,3) puts third column into vector v

Single row of a matrix: v=A(3,:) puts third row in vector v

Eigenvalues/eigenvectors:

[c,d]=spec(A) creates diagonal matrix d with eigenvalues in main


diagonal and matrix c whose columns are eigenvectors

You might also like