April 19, 2024, 05:57:50 AM
Forum Rules: Read This Before Posting


Topic: Program for balancing chemical equations  (Read 13953 times)

0 Members and 1 Guest are viewing this topic.

Offline woelen

  • Chemist
  • Full Member
  • *
  • Posts: 277
  • Mole Snacks: +40/-2
  • Gender: Male
  • The art of wondering makes life worth living...
    • Science made alive
Program for balancing chemical equations
« on: April 07, 2006, 05:20:22 PM »
I developed a program for balancing chemical equations. A beta-version of this program already was available, but now I present a new version, which allows the use of preserved groups (useful for organic chemistry) and the use of isotopes.

The program can be used for balancing any chemical equation, e.g. it nicely balances equations like the following:

..K2Cr2O7 + ..KCl + ..H2SO4 -> ..KHSO4 + ..Cr2O2Cl + ..H2O

The program determines the coefficients, needed to make it correct:

K2Cr2O7 + 4KCl + 6H2SO4 -> 6KHSO4 + 2Cr2O2Cl + 3H2O

The program can also do computations from moles to grams and vice versa and it computes weight ratios, needed for certain reactions. It also detects when a chemical reaction is non-stoichiometric (a nice example is the reaction between copper and nitric acid, where both NO and NO2 are formed) and the solution cannot be determined unambiguously. The program also allows the use of ions in the equations, so it can be used nicely for balancing equations, in which dissolved ionic compounds are involved, e.g. ions like Cl(-), Cr2O7(2-), MnO4(-), etc.

If you download the program, please also read the tutorial, before asking questions to me about the program.

Any feedback on the program, functionality, user interface, algorithms, is welcome.

The program is available at this page:

http://woelen.scheikunde.net/science/chem/chemeq/index.html

It is very easy to use, no installation needed, just click the icon and start playing....
Want to wonder? See http://www.oelen.net/science

Offline Borek

  • Mr. pH
  • Administrator
  • Deity Member
  • *
  • Posts: 27652
  • Mole Snacks: +1800/-410
  • Gender: Male
  • I am known to be occasionally wrong.
    • Chembuddy
Re:Program for balancing chemical equations
« Reply #1 on: April 07, 2006, 06:16:23 PM »
I developed a program for balancing chemical equations.

Me too ;)

Quote
A beta-version of this program already was available, but now I present a new version, which allows the use of preserved groups (useful for organic chemistry) and the use of isotopes.

No isotopes here, but you may define your own groups as well - and not temporarily, they are stored in the external text file (identical is used by all my other calculators BTW).

Plus limiting reagents, built in concentration and ideal gas calculators, reagents database and printed summaries for the reactions. Not to mention TXT/RTF/HTML/UBBC/LaTeX equation export like this:

2KMnO4 + 5(COOH)2 + 3H2SO4 -> 10CO2 + K2SO4 + 2MnSO4 + 8H2O

What I like about your program is better handling of the equations that can't be solved (better messages, displaying of several possible solutions), that's what I have to work on.
ChemBuddy chemical calculators - stoichiometry, pH, concentration, buffer preparation, titrations.info

Offline woelen

  • Chemist
  • Full Member
  • *
  • Posts: 277
  • Mole Snacks: +40/-2
  • Gender: Male
  • The art of wondering makes life worth living...
    • Science made alive
Re:Program for balancing chemical equations
« Reply #2 on: April 08, 2006, 03:29:17 PM »
Well, I concentrated on the mathematics behind the program and just implemented the basic things, but using advanced and complete mathematics (that is my strength and background, I have done a LOT of math in my work).
I use the program mainly on a small computer in my home lab, such that it can do tedious computations, which I otherwise have to do by hand. Using a small tablet PC, I have a nice chemical calculator, without any frills.

The mathematics behind the program are fairly complicated.

The program first determines a set of linear equations with integer coefficients, for each of the compounds, involved in the equation to be balanced.

This equation can be written as a matrix equation Ax = Bx. This can be rewritten as (A-B)x = 0. I determine the nulll-space of the matrix A-B. If the dimension of the null-space equals 0, then the reaction is not possible. An example of such a reaction is:

CuO + SO2 --> CuSO4

If the dimension of the null-space of the matrix A-B equals 1, then the equation can be solved unambiguously (except for a single factor). This is the situation, which usually occurs with high-school chemistry equations. If the dimension of the null-space is larger than 1 (e.g. 2, 3, ...), then the problem cannot be solved unambiguously. An example of that is given on my website (copper and nitric acid).

What the program also does is not only determining the dimension of the null-space, but it also tries to form a base for the null-space, with all-integer coefficients. Such a base always exists, because the input problem also is all-integer. The program also tries to find all base vectors such that all elements in them are larger than or equal to 0. This is not always possible. Sometimes negative values are needed. If that is the case, then it means that the compounds, which negative coefficients need to be brought to the other side of the arrow. An example of that also is on my website (the vanadium half-reaction in the tutorial page).

You should really try to understand the linear algebra behind the problem of balancing chemical equations. It makes the problem totally and completely solvable.

At the moment I'm thinking about the generic solving of acid/base problems, which takes into account the pKa or pKb values for all involved acids and bases, for all different protons, which can be split off or absorbed. It also takes into account the self-ionization of the solvent. The latter is important at very low concentrations of acids (e.g. 10^-8 mol/l of HCl in pure water has not a pH, equal to 8, but somewhere just below 7).
This is quite an easy problem as well. In general this results in a set of multivariate polynomial equations. These can be transformed to a large single polynomial equation. I already have a generic polynomial equation solver (it is on my website, MPSOLVE, basic algorithm from University of Pisa, I have made the algorithm much more robust, such that any ill-conditioned polynomial can be tackled). This will be the work-horse for the acid/base program. More info about this will follow later, when I have a reasonably working version of the program.
« Last Edit: April 08, 2006, 03:32:52 PM by woelen »
Want to wonder? See http://www.oelen.net/science

Offline Borek

  • Mr. pH
  • Administrator
  • Deity Member
  • *
  • Posts: 27652
  • Mole Snacks: +1800/-410
  • Gender: Male
  • I am known to be occasionally wrong.
    • Chembuddy
Re:Program for balancing chemical equations
« Reply #3 on: April 08, 2006, 03:40:37 PM »
The mathematics behind the program are fairly complicated.

Depending on the point of view. High school student will not understand a word of your explanation, for me the idea is rather obvious.

Quote
What the program also does is not only determining the dimension of the null-space, but it also tries to form a base for the null-space, with all-integer coefficients. Such a base always exists, because the input problem also is all-integer. The program also tries to find all base vectors such that all elements in them are larger than or equal to 0. This is not always possible. Sometimes negative values are needed. If that is the case, then it means that the compounds, which negative coefficients need to be brought to the other side of the arrow. An example of that also is on my website (the vanadium half-reaction in the tutorial page).

That's where I have stopped. I preferred to concentrate on the user interface.

Quote
At the moment I'm thinking about the generic solving of acid/base problems, which takes into account the pKa or pKb values for all involved acids and bases, for all different protons, which can be split off or absorbed. It also takes into account the self-ionization of the solvent. The latter is important at very low concentrations of acids (e.g. 10^-8 mol/l of HCl in pure water has not a pH, equal to 8, but somewhere just below 7).

Don't bother, such program exists. It is called BATE. And the math behind is described in details in the lectures on my site.
ChemBuddy chemical calculators - stoichiometry, pH, concentration, buffer preparation, titrations.info

Offline woelen

  • Chemist
  • Full Member
  • *
  • Posts: 277
  • Mole Snacks: +40/-2
  • Gender: Male
  • The art of wondering makes life worth living...
    • Science made alive
Re: Program for balancing chemical equations
« Reply #4 on: April 09, 2006, 06:33:43 AM »
Borek,

The programs I write finally have to become part of a suite, which can run on ultra low-profile hardware. Most programs I know are bloated too much. The executable size of my programs only is 85K on Windows and when compiled for an ARMv5 processor it shrinks to only 30Kbyte. This allows the use of the programs as if you were using a simple calculator, which starts up within one second or so. Besides that, I provide my programs for free. When they are completely worked out, then the source code also will be provided, as with the MPSOLVE workhorse.
Want to wonder? See http://www.oelen.net/science

Offline Borek

  • Mr. pH
  • Administrator
  • Deity Member
  • *
  • Posts: 27652
  • Mole Snacks: +1800/-410
  • Gender: Male
  • I am known to be occasionally wrong.
    • Chembuddy
Re: Program for balancing chemical equations
« Reply #5 on: April 09, 2006, 07:28:44 AM »
Regarding low hardware profile - none of my exes is above 500kB, none of my downloads (installer included) is above 500 kB, all my programs run flawlessly on 233 MHz Pentium (it doesn't mean they need it - I just don't have slower machine to check), and they are available as a suite (although not for free).

Why do I have that sad feeling that you are following my ideas?  :-\
ChemBuddy chemical calculators - stoichiometry, pH, concentration, buffer preparation, titrations.info

Offline woelen

  • Chemist
  • Full Member
  • *
  • Posts: 277
  • Mole Snacks: +40/-2
  • Gender: Male
  • The art of wondering makes life worth living...
    • Science made alive
Re: Program for balancing chemical equations
« Reply #6 on: April 09, 2006, 08:31:35 AM »
Quote
Why do I have that sad feeling that you are following my ideas?
Oh, come on  >:( ! Don't come with unfounded accusations! I already had the chemeq.exe program in 2001 and the numerical software, I use as the work horse for all the computations I already had long before. Some parts, such as the matrix algorithms, even go back to the end of the 1980's, please check out on my website. I used some of the materials of the networking software and you can see the sources of that. Only recently, however, when I started my website (last year, June), I decided to share some of my software through that as well. In the meantime I improved the software a little bit (adding the Windows user interface), but the main program already existed a much longer time as a command-line tool.

And besides that, I emphasize on other things. You put emphasis on ease of use (GUI, database of compounds, etc.) and I put emphasis on almost 100% robust mathematical algorithms and absolutely light weigt processing.

I have read the lectures on your website (I did not know them, but they are interesting). My approach will be different than yours. I do not trust Newton's method, because what you state about that is not always true, unless ALL roots of the polynomial equation are real and single. I did not analyse the equation for all roots, I only need one of them (you probably also need one, the largest positive one, I assume). I use a method based on an algorithm, developed by Dario Andrea Bini and Giuseppe Fiorentino from the university of Pisa. I do not use their algorithm straight out, but added my own improvements (cluster breakdown depending on stack size and automatic stack overflow anticipation in the root-clustering algorithms). This makes the algorithm essentially fail-safe. Much memory--> fast computations, tight memory--> more time needed for computation. I also use GMP as the workhorse.

For more info see: http://www.dm.unipi.it/pages/bini/public_html/papers/mps2.html
and http://www.swox/com/gmp

Want to wonder? See http://www.oelen.net/science

Offline Borek

  • Mr. pH
  • Administrator
  • Deity Member
  • *
  • Posts: 27652
  • Mole Snacks: +1800/-410
  • Gender: Male
  • I am known to be occasionally wrong.
    • Chembuddy
Re: Program for balancing chemical equations
« Reply #7 on: April 09, 2006, 08:57:41 AM »
Quote
Why do I have that sad feeling that you are following my ideas?
Oh, come onĀ  >:( ! Don't come with unfounded accusations!

It was not my intent to accuse you of anything and I apologize if that's the way you have read my post. But try to see the thing from my perspective - imagine how it feels reading "oh, and I am going to do a pH calculation program" and the "oh, and it will be a suite" - if these are exactly things I have spent last year doing.

I was copycatted with my dyslexia programs in Poland in 2004, in effect I have lost 2/3 of my income, thus I am very sensitive to such situations.

I suppose you will feel the same way if someone will post something like "hey, I have just started to do interesting experiments and I am describing them on my site, come and see how Mn2O7 violently reacts with different things!".
ChemBuddy chemical calculators - stoichiometry, pH, concentration, buffer preparation, titrations.info

Offline woelen

  • Chemist
  • Full Member
  • *
  • Posts: 277
  • Mole Snacks: +40/-2
  • Gender: Male
  • The art of wondering makes life worth living...
    • Science made alive
Re: Program for balancing chemical equations
« Reply #8 on: April 09, 2006, 02:07:52 PM »
OK, I accept your apologizes.

I've never had any intent to do harm to your business, I have developed my programs completely independent from yours and I develop this kind of programs already for quite a long time (one of my other hobbies besides home chemistry is scientific programming). I already made a program for simulating 3D physical models, based on bond graph methods and using a DASSL-like method for solving the resulting system of implicit algebraic/differential equations (this also will be posted soon). As you have seen on my website, I also made a program for simulating electronic linear networks and my last projects are the chemeq.exe program and the upcoming pH calculator.

To be honest, if my experiment with Mn2O7 makes someone else interested and that person also publishes a webpage on Mn2O7, then I only see that as a compliment and not as an infringement on my work. The only thing which would annoy me if people take pictures from my site and use them on their own as if they are their own product. If they do their own experiments, make their own pictures, and so on, then I just encourage them to do so.

But I understand your point. For you it is part of your income, for me it is just hobby (my income is from IT-consultancy in the business world, such as billing systems, customer relations, contract services and access/security software, not the kind of things which clash with my hobby-things). I always wanted a job in science, but I did not have the opportunity. So, I earn my money in business and do science at a hobby level in spare time.

What I can do is let you know the algorithms I use and keep in contact with you about the programs. I do not want to harm your business, but on the other hand, how can I distribute my programs without doing so? Maybe I can help you with your business if you have some technical questions, which you find hard to solve, especially if they are hard from a mathematical point of view. I think that your fully fledged programs, which are good-looking and have commerical value and my very bold and simple programs can coexist.

Want to wonder? See http://www.oelen.net/science

Offline pantone159

  • Mole Herder
  • Chemist
  • Full Member
  • *
  • Posts: 492
  • Mole Snacks: +54/-6
  • Gender: Male
  • A mole of moles doesn't smell so nice...
    • Go Texas Soccer!!
Re: Program for balancing chemical equations
« Reply #9 on: April 10, 2006, 11:10:01 PM »
I think it is great that both of you guys are making chemistry software.  More options, more ideas = good, in my book.

One of these days, I might get my 'internal home lab' software in some shape to offer, it makes no attempt whatsoever to balance equations.  Instead, I have an Excel spreadsheet that has tables of compounds and mixtures, and has tables for dilution calculations, nice labels to print, and simple things like that.  It is not at all sophisticated, but I find it useful.



Sponsored Links