I am supposed to be finding the first nonzero element in the row and initialising it to pivot but I am checking if pivot is zero later. How can a pivot be zero when pivots are supposed to be nonzero and even if it is, isn’t the whole row full of zeroes then
Yes, if there are no non-zero values in the row, then there is no pivot value and you have to handle that case differently. They give you the logical structure in the template code for where you need to handle that case and they tell you to use the “move row to bottom” function on the rows that are already all zeros.
If there are no non-zero values in the row, then the whole row will be full of zeros. So which column index to use for finding the non-zero row below the no non-zero row using this function template -
index = get_index_first_non_zero_value_from_column(M, column, starting_row)
It is still the same column index that you started with on this iteration. You then want to look down that same column and hope to find a non-zero entry. If you find it, then you swap that row with current zero row.
The input augmented matrix based on Exercise 1 -
M = [[1 2 3 1]
[0 0 0 2]
[0 0 5 4]]
The REF of this matrix I get after executing the Exercise 1 -
[[1., 2., 3., 1.],
[0., 0., 0., 1.],
[0., 0., 1., 0.]]
Is this REF correct for the above matrix? If so, don’t you think that it violates one of the conditions to be in REF - Every pivot is to the right of pivots on the rows above.
Row 2 has a pivot at index 2 however, Row 1 has a pivot at index 3.
Yes, it violates the definition as stated, but the output you show passes the test case. A bug has already been filed about this. Here’s a previous thread that also mentions the point you are making.