Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Lab_MATLAB_English_Part2.doc
Скачиваний:
2
Добавлен:
19.11.2019
Размер:
421.89 Кб
Скачать

Variant 9

1. The integer m,n and matrix A(m,n) are given. Calculate the amount of rows, which have zero elements.

2. The integer n and square matrix A(n,n) is given. Count up the average of even elements which are placed

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.

Variant 10

1. The integer m,n and matrix A(m,n) are given. Find columns in which there are more then 2 negative elements.

2. The integer n and square matrix A(n,n) is given. Count up the sum of negative elements which are placed

1) higher than main diagonal;

2) below than main diagonal;

3) on the main 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.

Variant 11

1. The integer m, n and matrix A(m,n) are given. Find the sums of elements for each row.

2. The integer n and square matrix A(n,n) is given. Count up the amount of elements which are the squares of integers which are placed

1) in rows which begin with negative elements;

2) in rows which begin with 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 12

1. The integer m,n and matrix A(m,n) are given. Calculate the amount of columns, which have zero elements.

2. The integer n and square matrix A(n,n) are given. Count up the amount of positive elements, which are placed

1) higher than main diagonal;

2) below than main diagonal;

3) on the main 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.

Variant 13

1. The integer m,n and matrix A(m,n) are given. Find the greatest element of matrix.

2. The integer n and square matrix A(n,n) are given. Count up the sum of odd elements, which are placed in

1) columns which begin with negative elements;

2) columns which begin with positive elements;

3) columns 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.

3.3 Example of Performance of Laboratory Work

Example 3.1. The integer m,n and the matrix A(m,n) are given. Input matrix elements from dialog window and output the matrix to worksheet. Output to worksheet too elements of matrix, which divided by 5 without rest.

Figure 3.1 – The worksheet with results of the example3.1

The text of the program for the decision of the problem:

Private Sub problem1()

Dim m, n, i, j, k As Integer

Dim a() As Integer

m = InputBox("Input amount of rows")

n = InputBox("Input amount of columns")

ReDim a(m, n)

Range("A1").Value = "Primary matrix A"

For i = 1 To m

For j = 1 To n

a(i, j) = InputBox("Input a(" & CStr(i) & "," & CStr(j) & ")")

Worksheets("Sheet1").Cells(i + 1, j).Value = a(i, j)

Next j

Next i

Worksheets("Sheet1").Cells(m + 2, 1).Value = "The elements of matrix which divided by 5 without rest"

For i = 1 To m

For j = 1 To n

If a(i, j) Mod 5 = 0 Then

k = k + 1

Worksheets("Sheet1").Cells(n + 3, k).Value = a(i, j)

End If

Next j

Next i

End Sub

Example 3.2. The integer m,n and the matrix A(m,n) are given. The positive elements of matrix increase twice.

Figure 3.2 – The worksheet with results of problem 2

The text of the program for the decision of the problem:

Private Sub problem2()

Dim m, n, i, j As Integer

Dim a() As Single

m = InputBox("Input amount of rows")

n = InputBox("Input amount of columns")

ReDim a(m, n)

Range("A1").Value = "Primary matrix"

For i = 1 To m

For j = 1 To n

a(i, j) = InputBox("Input a(" & CStr(i) & "," & CStr(j) & ")")

Worksheets("Sheet1").Cells(i + 1, j).Value = a(i, j)

Next j

Next i

Worksheets("Sheet1").Cells(m + 2, 1).Value = "New matrix"

For i = 1 To m

For j = 1 To n

If a(i, j) > 0 Then

Worksheets("Sheet1").Cells(i + 3 + n, j).Value = 2 * a(i, j)

Else

Worksheets("Sheet100").Cells(i + 3 + n, j).Value = a(i, j)

End If

Next j

Next i

End Sub

Example 3.3. The integer n and the square matrix A(n,n) are given. Input matrix from range start from cell A2. Matrix and results output to text boxes. Count up an average of even elements:

1) higher than main diagonal;

2) below than main diagonal;

3) on the main diagonal;

4) two from the cases indicated higher;

5) for all matrix (all three first cases).

A user chooses a necessary point by the check box of standard element ListBox, changing property Style=1-Check, (or property Multiselected = 2, extended).

The text of the program for the decision of the problem:

Private Sub CommandButton1_Click()

Dim n, i, j, s, s1, s2, s3 As Integer

Dim a() As Integer

n = InputBox("Input amount of rows and columns")

ReDim a(n, n)

For i = 1 To n

For j = 1 To n

a(i, j) = Cells(i + 1, j)

txtA.Text = txtA.Text & CStr(a(i, j)) & " "

Next j

txtA.Text = txtA.Text & vbCrLf

Next i

If List1.Selected(0) Then

For i = 1 To n - 1

For j = i + 1 To n

If a(i, j) Mod 2 = 0 Then s1 = s1 + a(i, j)

Next j

Next i

End If

If List1.Selected(1) Then

For j = 1 To n - 1

For i = j + 1 To n

If a(i, j) Mod 2 = 0 Then s2 = s2 + a(i, j)

Next i

Next j

End If

If List1.Selected(2) Then

For i = 1 To n

If a(i, i) Mod 2 = 0 Then

s3 = s3 + a(i, i)

End If

Next i

End If

s = s1 + s2 + s3

txtS.Text = CStr(s)

End Sub

Private Sub UserForm_Initialize()

List1.AddItem "higher than main diagonal "

List1.AddItem "below than main diagonal "

List1.AddItem "on the main diagonal "

txtA.Text = ""

End Sub

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