- •Features of the using MathLab package. Problems of linear algebra, working with functions in the MathLab.
- •Work with arrays
- •Work with vectors
- •Task of vectors
- •Application of data processing functions to the vectors
- •Memberwise operations with vectors
- •Input of matrices, simplest operations
- •Calculations with arrays
- •Three-dimensional graphic arts
- •Decision of the systems of linear equations
- •Change of colour palette of chart
- •Turn of chart, change of point of review
Work with arrays
An array is a well-organized, numbered set of homogeneous data, having one name.
Access to the separate array cells is carried out on an integer index, i.e. on the number of element in an array. Depending on the amount of indexes, defining position of element in an array, arrays are divided into one-dimensional (vector-row, vector-column), two-dimensional (matrices) and multidimensional.
MatLab presents all data as an array, even a number is a two-dimensional array with a dimension one on one.
Work with vectors
Vectors are the one-dimensional (linear) numerical sets of numbers, position of every element is set by a singular value - its number.
Task of vectors
>> a1=[3 4 9 2] it is a vector-row
>> a1=[3, 4, 9, 2] it is a vector-row
>> a1=[3; 4; 9; 2] it is a vector-column
Task 7.
Set two vector-rows s1 = (3, 4, 9, 2) and s2 = (5, 3, 3, 2), find their sum and natural logarithm from the sum.
Access to vector elements is carried out by the task of its index in brackets after a name. It is possible to address to the block of consistently located elements of a vector by means of ":".
For example:
>> w=[0.1 2.9 3.3 5.1 2.6 7.1 9.8];
>> w(4)
ans =
5.1000
>> w(2:6)=0;
>> w
w =
0.1000 0 0 0 0 0 9.8000
Array cells can be included in expressions. For example, for being middle geometrical for the first three array cells, it is possible to do following:
>> w=[0.1 2.9 3.3 5.1 2.6 7.1 9.8];
>> gm(1/3)
gm =
0.9855
Task of vectors by means of operation ":". Let it is required to form the one-dimensional array of numbers in a range from 3.7 to 8.947 with an increase 0.3. It is easily arrived at by means of operator "colon". It is possible to define by means of function length, how many elements got in a vector.
>> mas=3.7:0.3:8.947;
>> length(mas)
ans =
18
Application of data processing functions to the vectors
Function |
Application |
Note |
prod |
>> z=[3 2 1 4 6 -5]; >> p=prod(z) p = -720 |
Multiplying of vector elements |
length |
>> z=[3 2 1 4 6 -5]; >> p=length(z) p = 6 |
Determination of number of vector elements |
sum |
>> z=[3 2 1 4 6 -5]; >> p=sum(z) p = 11 |
Adding up of vector elements |
abs |
>> z=[3 2 1 4 6 -5]; >> p=abs(z) p = 3 2 1 4 6 5 |
Determination of the module of vector elements |
min |
>> z=[3 2 1 4 6 -5]; >> p=min(z) p = -5 |
Determination of minimum element of vector |
max |
>> z=[3 2 1 4 6 -5]; >> p=max(z) p = 6 |
Determination of maximal element of vector |
sort |
>> z=[3 2 1 4 6 -5]; >> p=sort(z) p = -5 1 2 3 4 6
>> z=[3 2 1 4 6 -5]; >> [p, ind]=sort(z) p = -5 1 2 3 4 6 ind = 6 3 2 1 4 5 |
Vector ordering on increase
The call sort with two target elements forms a file of indexes of elements coincidence of the ordered and initial files |
mean |
>> z=[3 2 1 4 6 -5]; >> p=mean(z) p = 1.8333 |
Calculation of mean arithmetic vector |
It is independently possible to know about the functions of data processing, executing the command help datafun.
Task 8.
Set a vector, consisting of elements (9.4, - 2.3, - 5.2, 7.1, 0.8, 1.3).
Find arithmetical mean elements of vector, using the functions sum and length. Check up a result, using the function mean.
Order a vector on increase, find minimum and maximal elements of vector and their indexes.
