Engineering With Python Rotating Header Image

Fitting Polynomials and Correlation Equations to Vapor Pressure Data – Solution

Solve the problem:

1. Fit the Data to a Polynomial

Below is the program output in IPython with values for the various data fits.

prob13IPythonOutputIt is a little confusing, but now you know why in the earlier post that the polynomial coefficients are ‘backwards’.   You see the polynomial defined as p = 0.0007449*x3 + 0.03945*x2 + 1.198*x + 24.46 instead of the common way of p = 24.46 + a1*x + a2*x2 +….

Now let me define these items (we want the lowest sse and the highest R-squared):

sse_3 = 204.733367 ( ‘sum of squared errors’ for the 3rd order polynomial)

R2_vp3 = 0.99961988 (‘R squared’ for 3rd order polynomial)

sse_log = 0.321997 (‘sum of squared errors’ for the Clapeyron equation fit)

R2_log_vp = 0.9915015 (‘R squared’ for the Clapeyron equation fit)

sse_ant = 0.0118258 (‘sum of squared errors’ for the Antione equation fit)

R2_ant_vp = 0.99968788 (‘R squared’ for the Antione equation fit)

Here is the plot for the polynomial fit


Not a bad fit from the visual examination and the R squared is good, but the sse is pretty large, at lower temperature and pressure the fit is not quite as good as at higher temperature and pressure.  Also, notice I forgot to put labels on this plot, but from the values Temperature is the y-axis and Pressure is the x-axis.  Let’s look at the Clapeyron equation fit.

2. Fit the Data to the Clapeyron Equation:

prob13clapeyronPlotAgain, I forgot to label the axis, but you can figure out which is which.  Not good practice, but remember, “Do as I say, not necessarily as I do…”.  Here the fit is not as good visually, but the sse is lower which means it fits better (errors cancel out) over the span of the plot.  Also, I used the 1st order polyfit as the easiest way to fit the transformed data.   Now, let’s look at the Antione equation.

3. Fit the Data to the Antoine Equation:

prob13antioneEqnPlotWow, the transformed data visually fits well and the sse is the lowest and R-squared is the best.  Also, I used the scipy.optimize.leastsq package to regress the transformed data.  See how well the data ‘fits’ over the entire span of the data.   Now, we know why we use Antione’s Equation to fit vapor pressure data.

What’s Next?

Well, I’ve completed the 10 problems of the ASEE 1997 problem set.  Was it useful for you?  I learned a fair amount and I hope you did too.  I intend to work a few more problems and then go into using GUI’s and grabbing data from the web.  For my next set of problems, I will work a few from the following journal article by Rosen, E.M. and Adams, R.N., “A Review of Spreadsheet Usage in Chemical Engineering Calculations”, Computers in Chemical Engineering, Volume 11, No. 6, pp. 723-736.  Come back and join me.  Even better, comment freely and share any problems you have worked.  Thanks.

Leave a Reply