Engineering With Python Rotating Header Image

Fitting Polynomials and Correlation Equations to Vapor Pressure Data – Programming Approach

Plan your solution:

  • Draw a picture, in this case, list all of your data and equations
  • 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 perform linear regression, so you want a ‘least squares’ package
  • You’ll want to plot the solution to get the information
  • Need a regression solver (scipy.optimize), statistical support(scipy.stats) and plotting package (Matplotlib,pylab)

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

prob13importPackages

Next, input your vapor pressure data into an array so that you can begin to manipulate the data.  Arrays are ‘objects’ (here is a good link) and are very flexible and useful for managing numbers.

Input your Vapor Pressure Data:

prob13inputArrayData

Set up and try the Polynomial Fit (try 3rd Order):

prob13polynomialFit

Now, you’ll notice that the polynomial coefficients are ‘backwards’ on line 38 above due to the way the coefficient output is put into an array.  I haven’t checked but there may be packages in the stats package that calculate the residual difference squared and R squared fit, but I went ahead and put them in for good measure.

Transform the Data and fit to the Clapeyron Equation:

prob13clapeyronEqn

Note that the lists have defined as ‘arrays’ and set type to ‘float’.  I don’t completely get the Python Types yet, but often I find setting them to float can help.

Transform the Data and fit to the Antione Equation:

prob13antioneEqn

Now, it’s ready to run.  In the next  post, we’ll examine the output and use that to answer the questions.

Leave a Reply