A curve-fitting method for experimental data

Kenyon College. Gambier. OH 43022 bulletin board. A Curve-Fitting Method for Experimental Data. Fred R. Hilgeman and Gary H. Richter. Southwestern ...
3 downloads 0 Views 1MB Size
edited by

the computer bulletin board

RUSSELL H. BATT

Kenyon College Gambier. OH 43022

A Curve-Fitting Method for Experimental Data Fred R. Hilgeman and G a r y H. Richter Southwestern University, Georgetown, TX 78626 Curve fitting by the method of least sauares has become routine with the advent

of fast digital devices. Various curve-fitting routines are readily available and inexpensive;' however, some specialized techniques must still bedeveloped by the individual for unique situations. One such special situation is an equation used to describe excess extensive thermodynamic properties such as excess volume of mixine. -. excess enthalvv .. of mixing, excess free energy of mixing, etc.? Typically used is an equation of the form:

x

87-2 X)

I t is convenient to adopt the notation, far j -1 ,...,m - l a n d k = I ,..., N,whereNis the number of data points Z. ,.k

= X k -x$+'

and zm,k

where the Bj's are coefficients to he determined. Note that the term for j = Ovanishes. Givenasetofdatapaints ( x ~ , y J , .. . , (IN, yN) and coefficients BI, , B,-I that determine such a function F, a measure of how much F misses the data points is given by

=Yk

(5)

Combining eqs 2,3, and 5 gives

...

Excess Extensive Property = F(x) = r ( 1 -

utility can then simultaneously display the data points and the curve. The function described in eq 1is apolynom i d of degree m that has the value zero a t x = 0 and x = 1. The following is an alternative way to present such a function:

A,(l

- 2x)j

(1)

j=o

where x is the mole fraction, m is the degree of the polynomial, and Aj's are coefficients to bedetermined. This function has thespecia1 property of having a value of zero a t bothx = O a n d x = 1. Thisnew method described below is especially suitable for computer solution, and the case m = 6 is used t o illustrate how the curve-fitting calculations can be performed on a PC by a standard spreadsheet program such as Lotus 1-2-3. This provides the convenience of using one spreadsheet both to record the data and t o calculate and graph the curve of best fit. A spreadsheet graphics

The method of least squares seeks to find the curve that best fits a given set of data points by regarding the Bj's as variables for which values are to be chosen so that E(Bi, ,Em-,) is as small as possible. By calculus, the partialderivativesat apointof minimum value must all be zero.3 So i t is necessary that, for i = 1,. ,rn - 1,

.. .

..

'

Statpro by Penton Software Inc.; SPSS by SPSS Inc.; Sigmaplot by Jandel Scientific. Olmsted, J. J Chem. Educ. 1986, 63. 538: Jackson, P. R.; Morcom. K. W. J. Chem. Thermodynamics 1987, 19, 125. Cheney, W.; Kincaid, D. Numerical Math ematics and Computing, 2nd ed.; Brooks1 Cole: 1985; pp 362-367.

The Computer Bulletin Board-A New Feature Column This issue of the Journal inaugurates The Computer Bulletin Board, a new feature column intended to complement John Moore's popular Computer Series. As the name suggests, The Computer Bulletin Boardwill publish short notes and articles describing new and innovative applications of hardware and commercial software packages to the teaching of chemistry. Snecificallv. Bulletin Board will oublish refereed manuscriots describinq new user-constructed hardware or .-..-. ,. The - Comouter - new applications of commerca l y ava laole hardware, and new app icatlons of c o m m e ~ c ~software al such as spreaosneets, scient lac word processors, eleclronc notebooks, and statistical, nJmer ca melhods, grapnics, and data oase management packages. Anicles oevoted to !he above topcs wi I no longer oe publisned n the Computer Series. The Computer Sernes wi I, however, conunue lo puolish a r k e s descrioing authors' own programs or addressing general issues relat ng to CompAng In chemical eoucat!on. The Computer Bulletin Board will not rev ew commercial software Authors wish ng lo contr o.te to The Computer BuNeth B o a r a s h o ~d suomil manuscrpts direct y to the Journateditorlal offices n Austin. wlrh indicat on that me manscripls sno, d be torwardeo to The Computer Bulletin Board e d t o r D rect submission to the editor of The Comouter Bulieti'n Board or of the Computer Series will delay editorial consideration. Manuscripts sno,~d not exceed lhree db-b e-spaced, typewr nen pages in englh, snoL d not nc .oe more tnan three figures and/or taoles, and must conform to the Journaisl) e guide1 nes a s p ~ ' ,ished on page 93 of tne January 1987 ssue. Copies Of sonware on floppy disks nee0 not be suomined. The pr mary cr~feriafor p ~ icat b on vu Il be innovation and wioe interesl and utility to the chemical education community ~

~~

~

~

~~

Russell H. Batt Kenyan College Gambier, OH 43022

A96

Journal

of Chemical Education

Taking the partial derivative of eq 6 with respect to Bi, rearranging terms, and using eq 7 gives

[-g

&? = & crjBi - c k ] aBi By cornhining eqs 4 and 8, it is seen that eoefficientsB~, ,B,-I must be chosen so that

.. .

With the availability of spreadsheet programs for personal computers, experimenters may find it convenient to have the above calculations built into a spreadsheet. Because Lotus 1-2-3 is a popular and typical spreadsheet program, it was used to illustrate the technique. After values of x and y are entered, one computes the values of r2, X ~ , . + , X ~ , Z ~ , X - ~ 2 z , - ~ 3 , -x(, r x - ~ 5and ,

+ ~ . ~ = [ ~ ' x - x ? ] [ ~ y(12) ]

This method of computation has several advantages. The first time through, the matrix solutions and the substitutions are rather tedious, but, as soon as the calculation is done once, new sets of data can be added Alsowith a minimum of time eaoended. ~ more data may be added to a spreadsheet with no additional work and the number of data points are limited by space on the spreadsheet disk (wellover 500 datapoints). A copy ofthe MACRO code for Lotus 1-23 users is available upon request. ~

Despite the troublesome algehra required to arrive at eqs 9-11, it is fairly easy to program a computer to find the coefficients BI, . .. ,B,-,. Note from eqs 5and 7 that simple nested loops can calculate the z's from the data points and the e's from the 2 s . There are standard routines to salve the system of simultaneous linear equations in eqs 9-11,' 4Cheney and Kincaid (footnote 3). pp 202-210.

~

.

~

~~~~~

x - rk At the bottom of the data columns these values are summed. Now the summations are inserted into eqs 9, 10, etc. For example, eq 9 would become

Acknowledgment One of the authors (FRH) is grateful to the Robert A. Welch Foundation of Houstan, Texas, for support of this research.

Volume 65

Number 4

April 1988

A97

~

~

-