Informatics1-2019/HW6

A MathWikiből
A lap korábbi változatát látod, amilyen Gaebor (vitalap | szerkesztései) 2019. december 2., 22:28-kor történt szerkesztése után volt.

Tartalomjegyzék

MatLab

6 points

The task is to write two matlab functions, each in one .m file. You have to attack these files to your email. The name of the files should be the same as the functions.

Magic Matrix (3 points)

Write a magicmatrix function that has two arguments: two positive integers n and m. The result should be a n\times m matrix with 0 and 1 values of a pattern where two ones are next to each other and the pattern goes diagonally up and right (two to the right, one upwards). This pattern should begin at every third line.

Example:

>> magicmatrix(12,10)
  1   1   0   0   0   0   1   1   0   0   0
  0   0   0   0   1   1   0   0   0   0   1
  0   0   1   1   0   0   0   0   1   1   0
  1   1   0   0   0   0   1   1   0   0   0
  0   0   0   0   1   1   0   0   0   0   1
  0   0   1   1   0   0   0   0   1   1   0
  1   1   0   0   0   0   1   1   0   0   0
  0   0   0   0   1   1   0   0   0   0   1
  0   0   1   1   0   0   0   0   1   1   0
  1   1   0   0   0   0   1   1   0   0   0
  0   0   0   0   1   1   0   0   0   0   1
  0   0   1   1   0   0   0   0   1   1   0

Elimination (3 points)

Write a function called eliminate with four arguments:

  • a matrix M
  • and three positive integers: i, j, k

The three integers mean two row indices and one column index. The function should return a matrix with the same size as M, but the jth row kth column element should be zeroed out with the ith row kth element. As part of the Gaussian elimination.

Example

 M =
    1     2     3
    4     5     6
    7     8     9
 >> eliminate(M, 1, 2, 1)
 ans =
    1     2     3
    0    -3    -6
    7     8     9
 >> eliminate(eliminate(M, 1, 2, 1), 1, 3, 1)
 ans =
    1     2     3
    0    -3    -6
    0    -6   -12
 >> eliminate(eliminate(eliminate(M, 1, 2, 1), 1, 3, 1), 2, 3, 2)
 ans =
    1     2     3
    0     1     2
    0     0     0
 >> eliminate(eliminate(eliminate(eliminate(M, 1, 2, 1), 1, 3, 1), 2, 3, 2), 3, 2, 3)
 ans =
    1     2     3
    0     1     2
    0     0     0
 >> eliminate(eliminate(eliminate(eliminate(M, 1, 2, 1), 1, 3, 1), 2, 3, 2), 2, 1, 2)
 ans =
    1     0    -1
    0     1     2
    0     0     0
  • If the ith row kth element is zero, then return the original matrix.
  • If not, then
    • Divide the ith row such that the kth element becomes 1
    • subtract the multiple of the new ith from the jth row such that the kth element in that row becomes 0

Deadline

2019 December 8th, 23:59

Személyes eszközök