Skip to content

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

Conversation

VikingScientist
Copy link
Contributor

With no use of numpys array datastructure. This might be a contested decision.


# Check to make sure matrix is good!
if (A[max_index][k] == 0):
print("matrix is singular! End!")
Copy link
Member

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.

Copy link
Member

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]
Copy link
Member

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.

Copy link
Member

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]
Copy link
Member

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.

Copy link
Member

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.

@jiegillet
Copy link
Member

Oh boy. All the mistakes I found in your code are also in @leios's Julia code. This might take a while :)

@VikingScientist
Copy link
Contributor Author

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

@jiegillet
Copy link
Member

Yeah I'll open an issue. Let's keep this PR in the fridge for a bit if you don't mind.

@VikingScientist
Copy link
Contributor Author

I sniped you and just opened an Issue

@june128 june128 added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Jul 2, 2018
@leios
Copy link
Member

leios commented Jul 2, 2018

@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.

@jiegillet
Copy link
Member

jiegillet commented Jul 3, 2018

@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.

@leios
Copy link
Member

leios commented Jul 3, 2018

@jiegillet Yeah, the issue #201 is probably the best place to discuss this.

@jiegillet
Copy link
Member

jiegillet commented Jul 3, 2018

Yeah, sorry, I just saw your comment there. I'm gathering my thoughts and I'll answer there.

@jiegillet
Copy link
Member

Update: the Julia code and chapter were updated and merged. Have a look and change your code accordingly.

@jiegillet
Copy link
Member

Still alive? I will close this PR if it's stale.

@jiegillet jiegillet closed this Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants