Results 1 to 15 of 15

Thread: Balancing Chemical Equations

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734

    Balancing Chemical Equations

    Alright, I have no idea how to start to solve these things, take for example this:

    K + Ca(OH)2 --> K(OH) + Ca

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Looking at it from the Math view the left side has (OH)2 which is 2 times (OH).
    The rigth only has one of them, so there is something missing.
    From the chemical point of view, I HAVE NO CLUE
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    K + Ca(OH)2 --> KOH + Ca
    is what's given right?

    then you need to make 2 OH's on the other side too:

    K + Ca(OH)2 --> 2KOH + Ca

    Then you need 2 K's on the left again:

    2K + Ca(OH)2 --> 2KOH + Ca

    done, all elements balance. remember you can only change the big numbers, not the "sub numbers".
    Have I helped you? Please Rate my posts.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    Sorry, I forgot to mention that I needed some help doing it programmatically, I already know how to do it by hand.

  5. #5
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    firstly you have to make it parse all the coefficient, elements (also when they're in brackets) and "sub numbers". That's going to be the tricky part, after that simply mulitply until it balances.
    Have I helped you? Please Rate my posts.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    I was thinking something like that would work, however, I was going to try to put the systems inside of a matrix, take the inverse of the matrix and multiply it by the right side of the equation i.e:

    Given Equations:

    0 = 2y - w
    0 = z - x
    0 = 3y - 2x
    1 = y
    Code:
      w    x     y    z
    [-1    0     2   0                 [w                [0
       0   -1    0   1        X         x        =        0
       0   -2    3   0                   y                  0
       0    0    1   0]                  z]                 1]
    Last edited by dsheller; Mar 3rd, 2004 at 03:05 PM.

  7. #7
    Junior Member
    Join Date
    Jan 2003
    Location
    53776564656E
    Posts
    24
    How were you planning to relate your matrix to the chemical formula? Are you going to have a system of equations that you want to balance simultaneously???


    (BTW, it would look better if you edited your post, formatting the matrix using a fixwidth font. Should be the case if you mark it as code or something.)
    Edit: Now it looks much better. Very nice!
    Last edited by jskog; Mar 7th, 2004 at 08:28 AM.

  8. #8
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Once you've parsed the data, why not just go to the first item on the left, then find how many of those exist on the right, then multiply to match the sides up? Then loop through each element on left. Then loop this n times, where n is the number of elements on the left.

    Only problem i see is when you have the same element on one side more than once.
    Have I helped you? Please Rate my posts.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    jksog: Yes I am goign to use a system

    Acidic: Yea, the exception case is the problem, there may be a point where there an element is on the right, or left, in 2 areas

  10. #10
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    Honestly, you could try brute forcing it. On today's computers (and even yesterday's), only equations with insanely huge (chemically speaking) coefficients would hurt speed.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    How would you brute it? Would you rather put random coefficients at random areas or loop through it sequentially and put stuff somewhere, because basically you need all combinations of numbers then add em.

  12. #12
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    I'd probably try sequential. You might do random; it may offer more optimization opportunities. Still, I have never seen a balanced equation using more than 20 as a coefficient, meaning you'd have to loop through it 20^3*19 (assuming 4 different molecules) or about 160,000 times (theoretical maximum). That really isn't much for a computer, especially if you optimize and pre parse.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  13. #13
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking optimisation

    plus...'optimisation' would almost cancel out everything

    consider the case we have:
    putting coefficient of Ca(OH)2 would force everything else, then all you would have to do is cancel out greatest common factor...

    U'll find that unless its a really weird equation, then you'll only need to loop over very few coefficients. If you choose ones with 2, 3 ,... you'll probably cut it down considerably
    sql_lall

  14. #14
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860
    No, he should design a neural network to do it... damn that would be cool.
    Don't pay attention to this signature, it's contradictory.

  15. #15
    Junior Member
    Join Date
    Jan 2003
    Location
    53776564656E
    Posts
    24

    Cool

    alkatran:
    yeah, that'd be cool! but how were you intending to use a NN in this case? it's not like we're dealing with a classification or clustering problem...
    Let me know, I'm curious!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width