Informatics1-2019/HW6

A MathWikiből
(Változatok közti eltérés)
(Elimination (3 points))
a (Elimination (3 points))
 
32. sor: 32. sor:
  
 
The three integers mean two row indices and one column index.
 
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 ''j''<sup>th</sup> row ''k''<sup>th</sup> column element should be zeroed out with the ''i''<sup>th</sup> row ''k''<sup>th</sup> element.
+
The function should return a matrix with the same size as ''M'', but the j<sup>th</sup> row k<sup>th</sup> column element should be zeroed out with the i<sup>th</sup> row k<sup>th</sup> element.
 
As part of the Gaussian elimination.
 
As part of the Gaussian elimination.
  
67. sor: 67. sor:
 
     0    0    0
 
     0    0    0
  
* If the ''i''<sup>th</sup> row ''k''<sup>th</sup> element is zero, then return the original matrix.
+
* If the i<sup>th</sup> row k<sup>th</sup> element is zero, then return the original matrix.
 
* If not, then
 
* If not, then
** Divide the ''i''<sup>th</sup> row such that the ''k''<sup>th</sup> element becomes 1
+
** Divide the i<sup>th</sup> row such that the k<sup>th</sup> element becomes 1
** subtract the multiple of the new ''i''<sup>th</sup> from the ''j''<sup>th</sup> row such that the ''k''<sup>th</sup> element in that row becomes 0
+
** subtract the multiple of the new i<sup>th</sup> from the j<sup>th</sup> row such that the k<sup>th</sup> element in that row becomes 0
  
 
== Deadline ==
 
== Deadline ==
 
2019 December 8<sup>th</sup>, 23:59
 
2019 December 8<sup>th</sup>, 23:59

A lap jelenlegi, 2019. december 2., 22:30-kori változata

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