A Marquardt nonlinear least-squares program for the Apple II or PET

techniques to ensure, and speed up, convergence (23, 24). Perhaps the best known method is that due to ... found it to converge the most rapidly of se...
0 downloads 3 Views 1MB Size
techniques to ensure, and speed up, convergence (23, 24). Perhaps the best known method is that due to Marquardt (16) which attempts to use the best features of linearization and steepest descent. The particular method we have used is that due to Meiron (251, as described by Pitha and Jones (241, who found it to converge the most rapidly of seven methods examined with their test data. The program offered is only suitable for least-squares optimization. The partial derivatives reauired are estimated numericallv, usine differences: errors

only drawback is that derivatives (of sometimes awkward forms) are needed. At some cost in speed, all derivatives can he approx~matedby finite differences. The Marquardt algorithm can he summarized as follows (28): A) Evaluate the residual error RE; if it is small enough, stop.

Here d, is a data point, x , is the ith set of independent varitime. Availability The programs offered are written for the Apple I1 Plus microcomputer with 48K of memory and a single disk drive. As the programs are written in the Applesoft dialect of BASIC, they should be readily translatable to other Microsoft BASICS, e.g., P E T or TRS-80, except for the graphic demonstration of the simplex method which uses the unique features of the Anole's eranhics. grams are' availahle for US$7 each, all from ~ r o f e s s hL. Glasser a t the above address. The disk is also availahle through Project SERAPHIM.

A Marquardt Nonlinear Least-Squares Program for the Apple II or PET

are to be determined by the fit. B) Evaluate the residual error's response to changes in the q as a Taylor series through quadratic terms.

The second term in the second derivative expansion (eqn. 4) is dropped, as an approximation. Then if B is a vector (of first derivatives of RE) and A the matrix (of second derivatives) while A is a vector of the displacements dq, in each parameter, the residual error is

+ AT A A = RE(qO)+ AT (B + A A)

C a r l Trindle University of Virginia, Charlottesvilie. VA 22901

Sometimes there is no simple way to plot chemical data so that a linear relation can be tested. In other cases the transformation to variables which produces a linear relation weights some data unfairly (26). In those cases a fit of data to some nonlinear form is necessary. Programs to fit simple higher order polynomials to data are commonplace; it is a simple exercise to program a microcomputer to produce a least-squares polynomial representation of nonlinear data. However. manv theoretical rewresentations of nonlinear data do not take the polynomial form. I have found the need to evaluate the best parameters in rate laws, computed potential functions in atoms, equilibrium expression, convolution integral representations of fluorescence decay, and low-temperature heat capacity expressions; none of these functions is a polynomial. A numher of numerical methods for nonlinear function fitting are known (27). These may he distinguished hy their use of derivatives of the functional form: Need Derivatives

NO Derivatives

Fletcher-Powell-Davydon Marquardt Steepest Descents

Simplex Pattern Search

by their "robustness," which is an indication of how tolerant they are of poor initial guesses: Robust

Delicate

Marquardt Simplex

Pattern Search Steepest Descents FPn

and by their speed of convergence Fact

Slow

Marquardt

Simplex

The Marquardt algorithm is attractive, fast, and reliable; its 566

Journal of Chemical Education

RE@) = RE(qO)t AT B

(5)

go corresponds to a minimum in RE@), the coefficient of A would be zero. C) Choose A so If

B+AA=O;A=-A-IB

+

and consider q0 A = q to he a better description of the least-squares optimized set of parameters. D) If need he, revise the step length A defined in the "steepest descents" direction; that is, altering q o by A will produce the most drastic decrease in RE. The matrix A may be ill conditioned, in which case inversion is unreliable. In the Marquardt method, A is replaced by A + XI. The parameter A is chosen so that A + XI is non-singular (det (A + XI) $ 01, and so that the step A(X) = (A + XI)-'B is guaranteed to decrease the residual error. Figure 5 may clarify the last remark. Let the RE surface he represented hy a contour map. The original point q Ohas a steepest descents direction defined locally. A very short step will surely lead to a lower RE. But a long step may in fact increase R E The step length is short if X is large, while it could 0. The parameter X provides a way for the he long if X method to pick its way through steep, jagged terrain. E) Return to step A. A program employing the Marquardt algorithm is usually available as part of the library of any computer center (NLWOOD is the name likely to he familiar to computercenter staff). A few similar programs are availahle (from commercial vendors) for popular microcomputers. We have made our Apple 11+ version, which has been developed and tested over the past year, available through Project SERAPHIM (NSF-DISE),Eastern Michigan University, Ypsilanti, MI 48197. The program requires APPLESOFT in ROM, 48KB memory, DOS 3.3, and one disk drive. Please enclose a check for $4 made out to "Project SERAPHIM, acct. #20350." A PETIVIC cassette tape is availahle as well; hut no provision has been made for disk storage on the PETIIIIC.

--

pH MLER INTERFACE for APPLE COMPUTER Figure 6.Circuit diagram of interface tor connecting recorder outputs of a pH meter to an Apple lt"compu1er.

~

~

Figure 5.Effect of step size on approach to the minimum on a residual-error Surface.

(An 8K expander is required for the VIC version). This tape may he obtained by sending a check for $3 to Project SERAPHIM.

The Apple pH Meter

Figure 7. The complete Applea pH meter.

R. K. Behm and G. L. Breneman, Eastern Washington University. Cheney. WA 99004.

large TV screen serving as a unique tool for demonstrations of pH and pH meters for larger classrooms. This pmject had two objectives: 1) to provide a large display suitable for viewing by an audience of 50 to 100 students or larger if sufficient monitors are availahle, 2 ) and to implement the project with commonly availahle and relatively inexpensive components using the Apple I1 computer. A Corning 125 digital pH meter was selected because of its analog recorder output and its digital readout for easy calibration and verification of computer performance. To take advantage of common narts on hand. the circu~tshown in Figure 6 was assem(29). The numbled bn an Apple ~ o h b y l ~ r o t o t y p i n oar-d g bers in aarentheses are the numbers of the ains on the hoard corresponding to the same numbers on the computer's peripheral connectors. The hoard is availahle from most Apple computer distrihutors for about $15 including appropriate information about its use. The interface implemented on this board consists of components availahle a t a cost of ahout $12. The design is straightforward and relatively easy to modify for diffirent applications. The unit could be used for demonstrations of other potentiometric measurements. A BASIC (Applesoft) program was written to read the output of the interface card (an integer from between 0 and 255). This was accomplished using a PEEK statement that addresses the data bus (30) corresponding to the slot on the Apple in which the card is plugged. The number is converted ~

to pH and is displayed on a meter simulated on a TV receiver or monitor screen (see Figure 7). The output from the card is continually read and converted so that any changes in pH are immediately registered on the meter by movement on the needle. In the past, our demonstrations using pH meters and plotting titration curves for large classes have been unsatisfactory. When real solutions on a real pH meter were used most of the students could not read the meter and when measurements were simulated usine a comouter disalav so been used. The comalete setua is shown in Figure 7. Both positive and registers the correct millivolt reading on the +I00 to -700 mV scale. Building this type of interface would also be a good lab project for a computer interfacing course. The student would gain familiarity with a common type of analog output from a number of chemical instruments. He would receive experience in the ever recurring need to convert analog signals to digital signals. Further, the student would learn in general how microcomputers make use of such data; and specifically, how the very commonplace Apple 11 computer can he interfaced. disk drive) to G. L. Breneman. Volume 60

..

Number 7

..

July 1983

567