Problem with Exercise 1 in Programming Assignment C1W2 - Gaussian Elimination

I try to solve the first exercise in assignment c1w2 (Gaussian Elimination), but can not figure out what I am doing wrong.
I need help from an instructor.

The grader give this error message:

Wrong output for test case check_matrix_1.
Expected:
[[ 1. 2. 3. 4. ]
[-0. 1. 1.3 1.7 ]
[-0. -0. 1. 2.33333333]].

Got:
[[ 1. 2. 3. 4. ]
[-0. 1. 1.3 1.7]
[-5. -0. 1. 4. ]].
3 Tests passed
1 Tests failed

I have been troubling with this for hours.
Please help me!

Please check your personal messages for instructions.

I’m getting this failed unit test, as well, and am unsure why.

I broke down the test’s A/B inputs, and am not sure why the last fails.
Is this an edge case we have to handle?

Thank you.

Wrong output for test case check_matrix_1.

Expected:
[[ 1. 2. 3. 4. ]
[-0. 1. 1.3 1.7 ]
[-0. -0. 1. 2.33333333]].

Got:
[[ 1. 2. 3. 4. ]
[-0. 1. 1.3 1.7]
[-5. -0. 1. 4. ]].
3 Tests passed
1 Tests failed

Not an edge case, its a normal test condition.

1 Like

Hi there, I am getting the same error as Espen and steven. Is there any chance someone could help me out? I have been going back through the videos to review the math and I am just not getting anywhere.

Thank you in advance!

It’s pretty clear that there is a problem with your code if you get the same result as shown above. Look at the result: what could cause the -5. vaue at index (2,0) of that matrix. The value at that position should be 0., right? So how could that error happen? Time for some debugging. Add some print statements to understand what your code is doing.

I keep getting that same error too. Have tried print statements and debugging but am at a dead end. Would appreciate it if someone could share how they fixed it? Many thanks,

please share your error screenshot without sharing any codes @kvw

This is the error:

w2_unittest.test_row_echelon_form(row_echelon_form)
Wrong output for test case check_matrix_1.
Expected:
[[ 1. 2. 3. 4. ]
[-0. 1. 1.3 1.7 ]
[-0. -0. 1. 2.33333333]].
Got:
[[ 1. 2. 3. 4. ]
[ 0.25 1. 1.25 1.5 ]
[ 2.5 -0. 1. 1.5 ]].
3 Tests passed
1 Tests failed

This is the section of code where I think I have the problem ** below - bottom line of code:

codes removed by moderator

Thank you so much for your help, I was just about to give up on this course.

please don’t post any codes on public post. it is against community guidelines, rather DM your codes @kvw

Ok, thanks for that, it is my first time on this forum, I have deleted the code.

From looking at the code that was edited out (the mentors can look at the edit history), the way you are computing value_below_pivot is incorrect, which is probably the cause of the error. Think about what the column index should be there. Why is j - 1 relevant to that? Keep in mind what the point is of that loop: we are marching down the rows in the same column to zero all the values below the pivot in the same column, right? So how would we express that in terms of the column index? Note that in most cases there is more than one row to traverse there, unless you happen to be processing the second to last row of the matrix.

Hi @kvw

The below code mentions you to use pivot_row, but you have used M[j]

Perform row reduction using the formula:
row_to_reduce → row_to_reduce - value_below_pivot * pivot_row

Also as pointed by @paulinpaloalto
for value below point, you are suppose to use the below code recall to calculate the value below point which in your case seems to be missing.
Update the column index to agree with the new pivot position

You were also suppose to create a column index for pivot candidate which you didn’t create as the reason might be using an obsolete copy!!

So I suggest you to get a fresh copy and re-do the assignment as I suspect
PART 2 - NOT GRADED. This part deals with the case where the pivot isn’t in the main diagonal.
The above part is part of exercise 1 and I do not see in your codes as per the codes I could.

refer the below link 1a, on to get a fresh copy of your assignment

Regards
DP

1 Like

That’s a good point @Deepti_Prasad. Sorry, I quit looking when I saw the first bug. Looks like there is more than one! :nerd_face:

1 Like

I know trying again and again with failure is not easy and encouraging but debugging skills actually improve when an error is tough to resolve as you are trying every way to resolve and getting better understandint at the codes.

When I used to get such frustration, I used to take a break, start fresh when I am ready to concentrate and focused on resolving the issue.

Hope you will keep trying!!! The excitement after too many trials and errors is too great to be left along, so all the best!!!

regards
DP

Thank you all for your help, it works now. That was so frustrating, I hope I do better with the next task! Thanks again, I would have given up without your advice.

2 Likes