PDA

Click to See Complete Forum and Search --> : Balancing Chemical Equations


dsheller
Mar 2nd, 2004, 05:19 PM
Alright, I have no idea how to start to solve these things, take for example this:

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

opus
Mar 3rd, 2004, 05:19 AM
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

Acidic
Mar 3rd, 2004, 06:24 AM
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".

dsheller
Mar 3rd, 2004, 06:43 AM
Sorry, I forgot to mention that I needed some help doing it programmatically, I already know how to do it by hand.

Acidic
Mar 3rd, 2004, 06:48 AM
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.

dsheller
Mar 3rd, 2004, 07:48 AM
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

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]

jskog
Mar 3rd, 2004, 10:54 AM
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!

Acidic
Mar 3rd, 2004, 01:23 PM
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.

dsheller
Mar 3rd, 2004, 02:06 PM
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

jemidiah
Mar 3rd, 2004, 05:56 PM
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.

dsheller
Mar 3rd, 2004, 07:59 PM
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.

jemidiah
Mar 3rd, 2004, 11:15 PM
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.

sql_lall
Mar 4th, 2004, 05:17 AM
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

alkatran
Mar 8th, 2004, 09:34 PM
No, he should design a neural network to do it... damn that would be cool.:rolleyes:

jskog
Mar 9th, 2004, 03:50 AM
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! ;)