title: How to balance a chemical equation in Python 2.7 Using matrices
body: <p>I have a college assignment where I must balance the following equation :</p>
  
  <p>NaOH + H2S04 --> Na2S04 + H20</p>
  
  <p>my knowledge of python and coding in general is extremely limited at the moment.
  So far I have attempted to use matrices to solve the equation.
  It looks like I am getting the solution a=b=x=y=0
  I guess I need to set one of the variables to 1 and solve for the other three.
  I'm not sure how to go about doing this, 
  I have had a search, it looks like
  other people have used more sophisticated code and I'm not really able to follow it!</p>
  
  <p>here's what I have so far</p>
  
  <pre><code>    #aNaOH + bH2S04 --&gt; xNa2SO4 +y H20
  
      #Na: a=2x
      #O: a+4b=4x+y
      #H: a+2h = 2y
      #S: b = x
  
      #a+0b -2x+0y = 0
      #a+4b-4x-y=0
      #a+2b+0x-2y=0
      #0a +b-x+0y=0
  
      A=array([[1,0,-2,0],
  
               [1,4,-4,-1],
  
               [1,2,0,-2],
  
               [0,1,-1,0]])
  
      b=array([0,0,0,0])
  
  
  
  
      c =linalg.solve(A,b)
  
      print c
  
  0.0.0.0
  </code></pre>