I just finished a program that can take a chemical equation as a string: "H2+O2=H2O" and return a list of coefficients that balances the equation.

Well, I just solved this equation:
"K4Fe(CN)6+KMnO4+H2SO4=KHSO4+Fe2(SO4)3+MnSO4+HNO3+CO2+H2O"
and got the correct answer of {10 122 299 162 5 122 60 60 188}, in 9 ticks on a TI-84+SE. Ridiculous! Needless to say, I'm incredibly excited about my program. I'll upload it as soon as I get my laptop back.

Edit: Okay, it's up. I uploaded it here as well as ticalc.org because ticalc.org is slow.
http://www.cemetech.net/programs/archives.php?mode=file&path=/83plus/basic/science/chemeq.zip
Everyone should try it!
great work, I was thinking about making one of these some time ago. a nice additional feature would be to write your own input routine that would allow subscripted numbers
Hmmm...I have Chemistryi AP next year, might have to try this. Razz
Okay, I have one thing left to implement. There's an infinite number of solutions to any chemical equation: {4 2 4} is equivalent to {2 1 2}. So in order to solve, I always set the first coefficient to 1. Then I'd get like, {1 .5 1}, and while there's nothing wrong with this, I'd like for it to always return integer coefficients in lowest terms. How would I figure out the denominators in each list entry?
Just divide the list through by the smallest element, so {0.5 0.2 1 0.3} would be divided by 0.2. You might have to repeat that until every element was an integer, and as an additional check, you could divide through by the GCD of all the elements.
Okay, I found a way to do this. For every non-integer element in the list, put it as a fraction in lowest terms and multiply the list by the denominator. You find the denominator by taking the GCF of 1 and the number; example: the GCF of 1 and 7/162 is 1/162. You can't use the built-in gcf( as it only works on integers, so you use the Euclidean algorithm to take the gcf.

An interesting note on this: this is how you can put a number into a fraction in a BASIC program. Find the GCF of 1 and the number; then the inverse of the GCF is the denominator, and the original number divided by the GCF is the numerator. Credit goes to Weregoose for discovering this usage of the Euclidean algorithm.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement