Engineering With Python Rotating Header Image

Solution of Equilibrium Equations – Programming Approach

Plan your solution:

  • Draw a picture, in this case, list all of your data
  • Remember the fundamentals and apply
  1. Draw your material or energy balance envelope (If necessary, list out your equations and problem data)
  2. Remember [Accumulation = In – Out + Source/Sink]
  • Think about what you need to do and the answer you want
  • You need to solve for the roots of several equations, so you need a solver package
  • You’ll want to print the solution to get the information

How to start your program:

  • With Ipython open, open your editor
  • Label your program (you’ll never remember it, go ahead and label it!)
  • Import the packages you’ll need for solving

henleyRosen1ImportPackages

Input Problem Parameters and Initial Conditions:

henleyRosen2InitialCond

Note, that x_int, the inital ‘advancement of reaction’, is input as a list with the A1,1 = Rxn 1 and A1,2 = Rxn 2.

Define the Equilibrium Reactions in a Function:

henleyRosen2SolveFunction

Note that the ‘fsolve’ function is included here.  It uses the function, ‘equil’ and the initial conditions for x.

Defining the Final Mole Amounts and Print (Get ready… it looks complicated):

henleyRosen2ConcentrationPrint

Now, this looks pretty complex… and it is.  It is really bookkeeping.  Keeping track of all of the compounds and how they are changing with respect to how the reaction proceeds.  Also, since the lines were long I used the ‘\’ continuation operator to break the command into two lines.  You have to be really careful and for several equations, it can be very long.  Is that what graduate students are for?  Sorry, I suffered as a grad student, it must be in the guild rules.  Stay around and we’ll post the answer in the next post.  You’ll say, we went to all that trouble for that!!

Leave a Reply