- •Contents
- •1 Laboratory work №1. The loop statements in matlab programs
- •2 Laboratory work №2. The work with arrays in matlab
- •3 Laboratory work №3. The work with matrixes in matlab
- •3.2 Tasks for laboratory work ……………………………….25
- •3.3 Examples of performance of laboratory work …………..29
- •1 Laboratory work № 1 Loop statements in mAtlab programs
- •1.1 Loop Statements
- •1.2 Tasks for Laboratory Work
- •1.3 Example of Performance of Laboratory Work
- •1.4 The Test Questions
- •2 Laboratory work № 2 The Work with Arrays in maTlab
- •2.1 Arrays
- •Matlab functions for arrays (vectors)
- •If a is a vector, sum(a) returns the sum of the elements. If a is a matrix, sum(a) treats the columns of a as vectors, returning a row vector of the sums of each column. Example
- •2.2 Main algorithms for working with arrays
- •2.3 Tasks for Laboratory Work
- •2.3 Examples of Performance of Laboratory Work
- •2.4 Test Questions
- •3 Laboratory work № 3 The Work with Matrixes in matlab
- •3.1 Multidimensional Arrays
- •Some elementary matrix functions and operations of transformation and decomposition
- •3.2 Tasks for Laboratory Work
- •Variant 1
- •Variant 2
- •Variant 3
- •Variant 4
- •Variant 5
- •Variant 6
- •Variant 7
- •Variant 8
- •Variant 9
- •Variant 10
- •Variant 11
- •Variant 12
- •Variant 13
- •3.3 Example of Performance of Laboratory Work
- •4 The list of books
3 Laboratory work № 3 The Work with Matrixes in matlab
3.1 Multidimensional Arrays
Sometimes you need to keep track of related information in an array. For example, to keep track of each pixel on your computer screen, you need to refer to its X and Y coordinates. This can be done using a multidimensional array to store the values.
Some elementary matrix functions and operations of transformation and decomposition
-
expm - Matrix exponential
Logm - Matrix logarithm
sqrtm - Matrix square root
norm - Matrix or vector norm
rank - Matrix rank
det - Determinant
trace - Sum of diagonal elements
inv - Matrix inverse
size - Size of array
reshape(x,m,n) - returns the m-by-n matrix whose elements are taken columnwise from x.
length - Length of vector
diag - Diagonal matrices
triu - Extract upper triangular part
tril - Extract lower triangular part
Execute the following commands:
A=reshape(1:24,4,6) triu(A) triu(A,0) triu(A,2) triu(А, -1) tril(A)
v=1:5 diag(v) diag(v,2) diag(v, -1)
diag(A) diag(A,2) diag(А, -1)
A=reshape(1:24,4,6) rot90(A) rot90(A,2)
The basic matrix operations :
А' |
- transposing of a matrix |
А+В |
- addition (subtraction) of matrixes |
А*В |
- multiplication of matrixes |
А/В |
- the right division of matrixes |
А\В |
- the left division of matrixes |
А^р |
- exponentiation of a matrix |
А.*В |
- on element multiplication of matrixes |
А./В |
- on element division of matrixes |
А.^р |
- on element exponentation of matrixes |
Execute the following commands:
m=3;n=4; a=rand(m,n) b=rand(m,n) c=rand(1,n)′
p1=a*b p2=a.*b p3=a*c p4=a.*c
3.2 Tasks for Laboratory Work
Variant 1
1. The integer m,n and matrix A(m,n) are given. Find rows in which there are more than three elements which are equal to zero.
2. The integer n and square matrix A(n,n) are given. Count up the average value of elements which are the squares of integers and which are located
1) in rows with the first negative elements;
2) in rows with the first positive elements;
3) in rows which begin with 0;
Create on the form the List box control, which allows user to select one or more items of task. (Set property Multiselected=2 Extended). Your program has to perform only selected items.
Variant 2
1. The integer n and square matrix A(n,n) are given. Find rows in which all elements are equal to zero.
2. The integer n and square matrix A(n,n) are given. Count up the sum of elements, which are the squares of integers and which are located
1) higher than side diagonal;
2) below than side diagonal;
3) on the side diagonal.
Create on the form the List box control, which allows user to select one or more items of task. (Set property Multiselected=2 Extended). Your program has to perform only selected items.