I am having an issue with exercise 2 in the Week 2 assignment for Gaussian Elimination.
First, the matrix “M” that is being loaded into the beginning of the assignment is already in reduced row echelon form… I cannot figure out why this is happening.
Also, I have used print statements to walk through the program step by step for several hours (I’ve been stuck on this for a week), but just cannot figure out what is going wrong here. I suspect the issue is with the “M” matrix that the program starts with before we are allowed to fill in the “None” to complete the program. Can anyone help me with this? I don’t want to give up on it. See screenshot of error below.
Thanks
hi @Beverett87
can you share a screenshot of the output for exercise 2 you got. please make sure not to post any grade cell codes here as it’s against community guidelines.
or if you are encountering any error share a screenshot!
Regards
DP
There are a number of test cases that are used to test your functions in this (and every) assignment. If you look at them, you should see that most of them are not already in “row echelon” form. But if they are, your code should still work, right? In other words, your code has to handle the fully general case.
The other general thing to say about debugging is that they give you very detailed instructions and examples that show what your code needs to do, including all the steps. So an important debugging approach is to take the sample test and first work it out with a pencil and paper using the steps in the instructions. Then add print statements to your code so that you can track when your code goes off the rails in terms of what is supposed to be happening.
Thank you for the response. I have edited my post to include a screenshot of the error message I am getting. The error message shows the matrix that is already in reduced row echelon form.
This is the back_substitution
function, so the point is that the input matrix needs to be in row echelon form and then your code converts it to “reduced” row echelon form. But if the input is already in the fully reduced form, then nothing bad should happen: your code should still work and you end up with the same result. But that error says that something is going wrong in your logic in that case.
I added print statements to my code to show the value of M that is passed in as the argument and then the final M that is computed, as well as the solution. Here’s what I see when I run the test case for that cell:
M initial =
[[1 0 0 5]
[0 1 0 6]
[0 0 1 7]]
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]]
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. ]]
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.]]
M final =
[[ 1. 0. 0. 19.]
[ 0. 1. 0. -2.]
[ 0. 0. 1. 1.]]
solution = [19. -2. 1.]
All tests passed
So you’re right that the first test case is already reduced, but nothing bad should happen in that case. Now you have to figure out why your code fails in that case.
OK thank you paulinpaloalto! I’ll try and figure out this error. I have something wrong for sure.
@Beverett87
@paulinpaloalto just gave a suggestion on how to check which step might be incorrect, add print statement to each step and match with what Paul shared, which ever doesnt matches, is the step you need to focus.
my suspect would be with the error you got is to check if you are using the right function when you are passing the M values.
if you are still finding it difficult, then please send screenshot of the grade cell codes by personal DM. Click on either of the mentor name, and then message.
Regards
DP
I got it figured out! I had to be careful with defining the “value” and replacing the updated row at the end. Thanks for you help.
3 Likes
That’s great news that you were able to find the solution based on the suggestions above. Onward!