We are ready to tackle a full chemical equation.
We will start by making a class to store the chemical equation and end with exporting a matrix. There are some middle parts that are important too.
Adding Formulas
Like we did with adding in formulas and how we entered in individual elements, I want to do something similar with formulas. This function will call the read formula function we previously did, keeping track of how many total formulas we have added to the equation, and differentiate between adding in products or reactants (products are before the arrow and reactants after).
Reading an Equations from Text
Parsing again …
This one won’t be nearly as bad as reading in formulas. We only have to worry about the single arrow that separates products and reactants, the plusses that separate formulas, and finally feeding these formula’s to our previously mentioned function to add them to the data structure. I will note that each formula will be indexed for ease of generating a matrix and matching up the final coefficients.
Printing the Equation
We need a way of displaying what we have stored in the data structure. We will not do anything fancy. We just want something that is readable.
Just three more things.
Master Element List
We will want to create a list of all of the elements that are used in the equation, both products and reactants. This will be used to check if the Equation is valid as well as generating a Matrix that we will chuck to rowEchelon.
Checking the Equation
After creating our master list of elements, we will make sure that each element in this list appears in both the products and reactants. This will be the only check of the user that will be performed.
The Matrix
Generating the matrix will not be that bad given everything else that will be handled before we get to this point.
Final Thoughts
We are getting close. At the end of the next post, we will see everything we have done so far work together. After that, the only thing left is to create the solution from a row echelon matrix.
Recent Comments