-
-
Notifications
You must be signed in to change notification settings - Fork 360
Added python gaussian elimination #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added python gaussian elimination #200
Conversation
|
||
# Check to make sure matrix is good! | ||
if (A[max_index][k] == 0): | ||
print("matrix is singular! End!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Singular matrices have nothing to do with Gaussian elimination. If your pivot is zero, you continue with the next column. It's still a valid matrix in the echelon form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://stackoverflow.com/questions/23985004/gaussian-elimination-of-a-singular-matrix
In my understanding a singular matrix was indicative of an improper set of systems of equations and should be underdetermined. This algorithm shouldn't work for this case (I don't think, anyway). Most example code I can find stops once the matrix is considered singular; however, I think you are right. We can also take the general case. I am just not sure the best version of the code here.
for i in range(k+1,rows): | ||
|
||
# Step 3: finding fraction | ||
fraction = A[i][k] / A[k][k] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pivot is not always in the diagonal, in the case that a previous pivot was zero. You have to consider this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually related to the above discussion, I think. The code I have in the algorithm archive is meant to solve a system of equations, so these cases will be caught by the "singular matrix" condition.
soln = [0]*rows | ||
|
||
# initialize the final element | ||
soln[-1] = A[-1][-1] / A[-1][-2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again here, this is not general, in case the Echelon form is not a pure upper triangular matrix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this is caught by the "not singular" condition.
Currently looking at the code and seeing how we should update things.
Oh boy. All the mistakes I found in your code are also in @leios's Julia code. This might take a while :) |
Yup. This is a direct port of the Julia code. Might create an issue to fix that? BTW, the exact same errors appear in #195 |
Yeah I'll open an issue. Let's keep this PR in the fridge for a bit if you don't mind. |
I sniped you and just opened an Issue |
@jiegillet is right, the form we have in the AAA is not general; however, it is the most common implementation of the algorithm I could find. The current implementation solves a system of equations, which is what the chapter was set up to do. It can also find the determinant; however, it lacks the capability of finding the ranks and bases of a matrix, which means that it cannot be used for all cases. I'm currently looking at how to update the code from here. |
@leios I was thinking about it yesterday, and yes, if the problem you are working on is solving a system of equations, then the algorithm is perfectly adequate. However, Echelon and Reduced Echelon Forms have more applications than that, for example finding the rank of a matrix. It seems a little bit wasteful to implement the general case 90% of the way and stop there. |
@jiegillet Yeah, the issue #201 is probably the best place to discuss this. |
Yeah, sorry, I just saw your comment there. I'm gathering my thoughts and I'll answer there. |
Update: the Julia code and chapter were updated and merged. Have a look and change your code accordingly. |
Still alive? I will close this PR if it's stale. |
With no use of numpys
array
datastructure. This might be a contested decision.