Back Substitution Function Problem
My back_substitution function passed unit tests but failed some grading test cases.
Could I get some help about how to improve the function? Are there some edge cases I should take into account?
Back Substitution Function Problem
My back_substitution function passed unit tests but failed some grading test cases.
Could I get some help about how to improve the function? Are there some edge cases I should take into account?
most of the learners have got such failed output in two cases, either incorrect indexing in row echelon form, especially for pivot candidate, so make sure the first pivot candidate is in the diagonal, so column is equal to row. another issue would using incorrect function like using global variable instead of local assigned variable.
Regards
DP
Interesting. The tests in the notebook cover three different cases, so it’s a little surprising that you could pass those and then fail all three of the grader tests. My first theory would be that you clicked “Submit” without first clicking “Save”. Meaning that you had fixed a bug in the code in the notebook and not saved it, so that the code the grader got was different than what you are actually running in the notebook.
Just to make sure that everything is in sync, I would try this:
Kernel -> Restart and Clear Output
Save
Cell -> Run All
Then check the output in the notebook and make sure it still passes. If yes, then click “Submit” and see what happens.
If you get the same results you told us about with that method (pass the notebook tests and fail the grader), then there must be a real bug. In that case, I added some print statements to my back_substitution code to see how things are working and here’s what I see with the notebook tests:
M initial =
[[1 0 0 5]
[0 1 0 6]
[0 0 1 7]]
row 2
sub_row = [0 0 1 7]
j 0
row_to_reduce [1 0 0 5]
M [[1 0 0 5]
[0 1 0 6]
[0 0 1 7]]
j 1
row_to_reduce [0 1 0 6]
M [[1 0 0 5]
[0 1 0 6]
[0 0 1 7]]
row 1
sub_row = [0 1 0 6]
j 0
row_to_reduce [1 0 0 5]
M [[1 0 0 5]
[0 1 0 6]
[0 0 1 7]]
row 0
sub_row = [1 0 0 5]
M final =
[[1 0 0 5]
[0 1 0 6]
[0 0 1 7]]
solution = [5 6 7]
M initial =
[[ 1. 2. 3. 4. ]
[-0. 1. 1.3 1.7 ]
[-0. -0. 1. 2.33333333]]
row 2
sub_row = [-0. -0. 1. 2.33333333]
j 0
row_to_reduce [1. 2. 3. 4.]
M [[ 1. 2. 0. -2.99999999]
[-0. 1. 1.3 1.7 ]
[-0. -0. 1. 2.33333333]]
j 1
row_to_reduce [-0. 1. 1.3 1.7]
M [[ 1. 2. 0. -2.99999999]
[ 0. 1. 0. -1.33333333]
[-0. -0. 1. 2.33333333]]
row 1
sub_row = [ 0. 1. 0. -1.33333333]
j 0
row_to_reduce [ 1. 2. 0. -2.99999999]
M [[ 1. 0. 0. -0.33333333]
[ 0. 1. 0. -1.33333333]
[-0. -0. 1. 2.33333333]]
row 0
sub_row = [ 1. 0. 0. -0.33333333]
M final =
[[ 1. 0. 0. -0.33333333]
[ 0. 1. 0. -1.33333333]
[-0. -0. 1. 2.33333333]]
solution = [-0.33333333 -1.33333333 2.33333333]
M initial =
[[ 1. 5. 6. 9. ]
[-0. 1. 1. 1.64285714]
[ 0. 0. 1. 0. ]]
row 2
sub_row = [0. 0. 1. 0.]
j 0
row_to_reduce [1. 5. 6. 9.]
M [[ 1. 5. 0. 9. ]
[-0. 1. 1. 1.64285714]
[ 0. 0. 1. 0. ]]
j 1
row_to_reduce [-0. 1. 1. 1.64285714]
M [[ 1. 5. 0. 9. ]
[-0. 1. 0. 1.64285714]
[ 0. 0. 1. 0. ]]
row 1
sub_row = [-0. 1. 0. 1.64285714]
j 0
row_to_reduce [1. 5. 0. 9.]
M [[ 1. 0. 0. 0.7857143 ]
[-0. 1. 0. 1.64285714]
[ 0. 0. 1. 0. ]]
row 0
sub_row = [1. 0. 0. 0.7857143]
M final =
[[ 1. 0. 0. 0.7857143 ]
[-0. 1. 0. 1.64285714]
[ 0. 0. 1. 0. ]]
solution = [0.7857143 1.64285714 0. ]
M initial =
[[1. 8. 6. 9.]
[0. 1. 8. 6.]
[0. 0. 1. 1.]]
row 2
sub_row = [0. 0. 1. 1.]
j 0
row_to_reduce [1. 8. 6. 9.]
M [[1. 8. 0. 3.]
[0. 1. 8. 6.]
[0. 0. 1. 1.]]
j 1
row_to_reduce [0. 1. 8. 6.]
M [[ 1. 8. 0. 3.]
[ 0. 1. 0. -2.]
[ 0. 0. 1. 1.]]
row 1
sub_row = [ 0. 1. 0. -2.]
j 0
row_to_reduce [1. 8. 0. 3.]
M [[ 1. 0. 0. 19.]
[ 0. 1. 0. -2.]
[ 0. 0. 1. 1.]]
row 0
sub_row = [ 1. 0. 0. 19.]
M final =
[[ 1. 0. 0. 19.]
[ 0. 1. 0. -2.]
[ 0. 0. 1. 1.]]
solution = [19. -2. 1.]
All tests passed