Engineering With Python Rotating Header Image

Calculate a Four-Component ‘Flash’ – 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, not in this case)
  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 root of an equation, 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


Input the Data for Solving the Problem (Scipy arrays again, oh boy!):


Note the x = [].  That initializes a list named ‘x’ so that we can fill it with data later.  Also, I have a list called ‘name’.  More on that in a moment.

Set up Function for Solution:


Here we have set up the function for solution.  It is a ‘brute force’ approach.  Each portion is spelled out with the component name.  You could probably streamline it with a ‘for’ loop or something similar.  I’ll leave that as an ‘exercise for the reader’.  For me, doing it this way takes a little longer up front, but when I come back days, weeks, months later, I can easily figure out what the heck I was doing.  Also, note the data in Scipy arrays and the ‘sum’ is the return value.

Solve the Equation and Print the Solution:


Note the  x.append().  That fills our ‘x’ liste with the individual values that we can then print and sum.  The sum is to ensure the values add up to 1.0 as a check on the solution.  If they don’t add up to 1.0 exactly, you don’t have the right answer and can’t pass Go or collect $200.  Now, we have our program, we can proceed to the solution.  Stay tuned…

Leave a Reply