I was wondering if anyone would be able to provide help with a logical method of finding a redundant equation in a system of linear simultaneous equations. By 'redundant', I mean that I want to be able to find an equation which could be removed without preventing solutions from being found to the system of equations.

For example, if the system states that 'a=1 and b=2' then neither equation is redundant because information is lost by removing either equation. However, if the system states that 'a=b-1, a=1, and b=2' then any one (but not more than one) of these equations could be removed without any information being lost. Another example of a system with redundant equations would be if 'a=b, a=2, b=2, c=1, and d=c'. I could remove any one (but not more than one) of the first three without losing any information, but neither of the last two equations can be removed.

The reason that I want a way to find the redundant equations is because I am making a program that will convert chemical equations into a system of simultaneous equations, then will solve the simultaneous equations and use the solutions to balance the original chemical equation. The function that I have made that solves the simultaneous equations does not work if there are any redundant equations, which is why I need a logical method for how to fnd any redundant equations, as I will make the computer remove a redundant equation before solving. The user cannot just change the way that they type in the chemical equation, because that would defy the laws of chemistry.

Thank-you in advance.

  • $\begingroup$ The usual algorithm for solving systems of equations, Gaussian elimination, works whether the system contains "redundant" equations or not, and it is also probably the best way to find redundant equations. Why not just use it as your algorithm? $\endgroup$ – G Tony Jacobs Sep 4 '17 at 19:14
  • $\begingroup$ I'm already using a method that involves matrices, and I think that this is Gaussian elimination (but I could be wrong). The method that I'm using involves finding the inverse of a matrix, and (as far as I'm aware) only square matrices actually have an inverse. If there are any redundant equations, then surely the matrix can't be square? $\endgroup$ – Purple dragon unicorn Sep 4 '17 at 19:20
  • $\begingroup$ If you want the person to whom you’re replying to know that you’ve replied, include his name preceded by @ in your comment. $\endgroup$ – amd Sep 4 '17 at 19:36
  • $\begingroup$ As for the problem you’re trying to solve, Gaussian elimination will solve the system regardless of the presence of redundancies. What you’re describing doesn’t sound like Gaussian elimination to me. Indeed, if there are redundancies, then the coefficient matrix of the system will be singular, so the method you’re using will likely fail, anyway. $\endgroup$ – amd Sep 4 '17 at 19:40
  • 1
    $\begingroup$ For balancing chemical equations, I’d especially expect there to be redundancies when the system’s matrix is square since the coefficients that balance a chemical equations aren’t unique. E.g., $\mathrm{2H_2+O_2\to2H_2O}$ is balanced, but so is $\mathrm{6H_2+3O_2\to6H_2O}$. In linear algebra terms, the matrix of the system will have a non-trivial null space. $\endgroup$ – amd Sep 4 '17 at 20:14

As those in the comments have said, the way to really solve such a problem is via Gaussian Elimination

In Python this is easily implemented either from first principles using lots of for loops and summations. But an even easier (and faster!) solution is to use the NumPy package routine "numpy.linalg.solve".

You are quite correct that the matrix must be square and of full rank in order for you to be able to solve it.

[Aside note: A square matrix is full rank if and only if it's determinant is nonzero.]

Using numpy.linalg.solve(A,B) is neat as it will raise an error "LinAlgError" if A is singular or not square. The example given at the bottom of the documentation page is entirely self explanatory, so I will not insult your intelligence by going over it again!

So you could do something like this, but you'd need your chemist to already have written the thing up as a matrix or you could be kinder to them and write a little code to create the matrices from the equations they enter as plain text (e.g. https://stackoverflow.com/questions/45220032/how-to-balance-a-chemical-equation-in-python-2-7-using-matrices/45220319)

A = input("Enter the coefficents of your matrix: ")
B = input("Enter the ordinate values: ")
x = np.linalg.solve(A, B)
print x

Hope this helps, have fun and good luck! :-)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.