Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
labScilab_English_Part1.doc
Скачиваний:
26
Добавлен:
07.02.2016
Размер:
2.38 Mб
Скачать

Input of vectors (arrays)

Row vectors can be declared using brackets:

>> row_v = [0 1 2]

row_v =0 1 2

To declare column vectors, we use semi-colon at the end of each line:

>> col_v = [0;1;2]

col_v =0

1

2

It is also possible to transpose vectors using the apostrophe (asterisk):

>> col_v = row_v’

col_v =0

1

2

>> row_v = col_v’

row_v = 0 1 2

The colon (:) command easily built the vector. To build an array x of x-values starting at x = 0, ending at x = 1, and having a step size of h =0.1 type this:

>> x=0:0.1:1

The colon is the incremental operator in SCILAB (with default value set to 1):

>> row_v2 = [0:5] // using default increment

row_v2 = 0 1 2 3 4 5

>> row_v3 = [0:0.2:1] // using a different increment

row_v3 = 0.2000 0.4000 0.6000 0.8000 1.0000

Row vectors can be declared using function

linspace(start_value,end_value,amount_of_values)

-->linspace(1,5,9)

ans = 1.000 1.500 2.000 2.500 3.000 3.500 4.0000 4.5000 5.0000

Input of matrixes

A(i, j) - an element i-line and j-column.

A(k) - k-element of the table extended in a column.

Indexes (i, j) always begin with 1.

Matrices are defined by entering the elements row by row. Command

>>M = [1 2 4; 3 6 8];

creates the matrix M = [1 2 4

3 6 8].

There are a number of special matrices that can be defined:

null matrix: M = [];

n-by-m matrix of zeros: M = zeros(n,m);

n-by-m matrix of ones: M = ones(n,m);

n-by-n identity matrix: M = eye(n).

Examples:

A particular element of a matrix can be assigned:

--> M(1,2) = 5;

places the number 5 in the first row, second column.

The colon by itself refers to all the elements of the j-th column of A.

--> b=M(1,:)

b=1 2 4

Some operations with matrixes with use of the operator ":"

А(:, j)

refers to all the elements of the j-th column of A

А(:, j:k)

refers to the all elements from j to k columns of А

А(і,:)

refers to all the elements from i-row of matrix A

А(i:k,:)

refers to the all elements from i to k rows of matrix A

А(:)

refers to all the elements of a matrix A

Function size returns Size of array.

The function length() is related to size(). For a matrix with numeric elements length() returns the number of elements.

Concatenation is the process of joining small matrices to make bigger ones. In fact, even the simplest matrix is formed by concatenating its individual elements. The pair of square brackets, [], is the concatenation operator. In this example a 4x4 matrix has been created by concatenating four 2x2 matrices.

Input from keyboard

To have a script request and assign a value to the variable N from the keyboard use

N=input(“ Enter a value for N - “)

You can enter only a single number, like 2.7, then N will be a scalar variable. The load function reads binary files containing matrices generated by earlier SCILAB sessions.

Execute the following commands:

A=[1,2;3,4] A=[1;2,3;4] А(2,2) А(3) А(5) size(A)

А(3,4)=10 size(A) А(5)=6 size(A) А(22)=3 A=A(:) А(22)=3

size(A) [m,n]=size(A)

A=reshape(1:24,4,6) size(A)

А([1,end],:)=[ ] А(:,[1,end])=[ ] size(A)

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]