Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Laboratory work 5.1eng.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
3.47 Mб
Скачать

Input of matrices, simplest operations

For storage of matrices two-dimensional arrays, having an unique identifier, are used in the system MatLab. Access to the array cells is carried out through two indexes: line and number of column numbers, indicated in brackets, for example c(2,3), or by means of one index, for example c(1), which sets the sequence number of element of matrix in a vector, because matrix A measuring m on n in memory of computer kept as a vector of length mn, in which the elements of matrix are located in sequence string by string.

In the system MatLab vector appear as a row-vector and vector-column. The input of such vectors is designed variously:

>> a1=[3 4 9 2] it is a row-vector

>> a1=[3, 4, 9, 2] it is a row-vector

>> a1=[3; 4; 9; 2] it is a vector-column,

therefore the matrices of small dimensions can be entered or:

on lines

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

a =

3 1 -1

2 4 3

or column-wise

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

a =

3 1 -1

2 4 3

In order to know the sizes of two-dimensional array and "geometry" of vectors (vector-columns or row-vectors), it is needed to use the function of size.

>> size(a)

ans =

2 3

The first is show the number of lines, second is a number of columns.

Access to the elements of matrices is carried out through two indexes - row and column, put in round brackets numbers.

Task 18.

Enter the one-dimensional array b (1, 2, 3), as row-vector, know those its size by means of function of size, enter the array b1 (1, 2, 3), as vector-column, know its size, enter the variable of m = 5, know her size.

From the got results evidently, that even numbers (scalar sizes) the system MatLab interprets as two-dimensional arrays with the size of 1х1. Vector examined, as matrices the size of which on one of indexes is equal to 1.

The structure of the created arrays can be known yet by means of command whos.

>> whos

Name Size Bytes Class

a 2x3 48 double array

b 1x3 24 double array

b1 3x1 24 double array

m 1x1 8 double array

Calculations with arrays

With arrays of identical sizes the operations of addition (+) and substraction (-) are assumed.

For the memberwise multiplication and division of arrays the signs of ".*" and "./" (right memberwise division) are used.

There is yet the left memberwise division. Sign "\". Difference between them is such:

A ./ B

A .\ B

A(k, m) / B(k, m)

B(k, m) / A(k, m)

Usual signs "*" and "/" intended in the system MatLab for other operations: "*" in linear algebra, and "/" for being of roots of the systems of linear equations.

Transponation of matrix, similarly as well as vectors made by means of symbols ".'".

Task 19.

1. Enter matrices

2. Find the sum of elements of the second line of matrix B.

3. Find a sum and difference of matrices A and С.

4. Multiplication of matrices A and С.

5. Multiplication of matrices A and B, B and А.

6. Multiplication of number 3 on A, and A on 3.

7. Involution 2 a matrix B.

8. Make memberwise involution 2 matrix В.

9. Find the value of next expression

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