Formulation of Mathematical Expressions to Avoid Inaccuracies in Computation Shyam S. Shukla and Alka Shukial University of Connecticut Storrs. CT 06268 The blind acceptance of the result in a calculator display by students has been noted by several authors ( 4 , 5 ) .The computing devices are, however, not infallible. It must be realized that these devices are finite in nature. A simple example is the representation of the value of a,which is of infinite length. Obviously this value cannot be stored in the computer, and it must be truncated in some fashion, causing an error. This error may appear to be small, but its propagation through a computation can cause serious errors in the final result (6, 7). Consider, for example, the following quadratic equation (8), oXz+bX+e=O (1) whose roots (XI, X2) are given by Mathematically, eq 2 is correct, hut its truism by no means guarantees a correct computational result. Let us examine this statement by defining a = 1, b = -80 and c = 1 and taking a computer capable of holding only three decimal dieits. Since almost all scientific calculations are done in Ilwitlng point, the values 01 the coefficient on our nmpuler have to heexwressrd nso = O.lOU x lb', h = -0.800 X 10'and c = 0.100 X i0'. Using these values in eq 2 one gets the value of X I as 0.800 X lo2while that of Xz as zero. The reason for the second root being zero is that the value of 4ac (=0.400 X 10' = 0.0004 X lo4)is sufficientlysmall relative to h2 (=0.640 X 10') that it rsnnot br represented prup~rlvhyour cotnputer jahirh only holds three decimal digits,. The value of 4nc is, therefore, iounded to zero, causing the value of the second root to he zero. I t may he noted that on a more accurate computer the value of Xp may not be zero, hut its value will still be relatively inaccurate. How can this problem be avoided while still using the same computer? I t should he noted that the product of XlX2 is equal to cla. So that the value of X2 can be calculated as c/aX1. By doing so we get X2 = 0.125 X lo-' as opposed to avalue of zero obtained previously. But how do we know which answer is the correct one? One way to determine this is to reconstruct the original equation using the computed value of the roots. I t is easy to verify that the second set of the values are the correct ones. Thus, by proper reformulation of a mathematical expression we have avoided aserious problem. There are many ixpressions where similar problems can influence the result seriously. Let us consider another example; evaluation of ex - 1for small values of X. As X becomes small the value of ex tends toward 1 . Since we are now subtracting numbers of almost equal magnitude several significant figures are lost due to the cancellation error. Cancellation, i t must he noted, is the weakest link in any computation.Such problems can be avoided hvreformulation of the mathematicalex~ression.In our example it can he done by expanding the exponential function into a series so that ex-1=1+X+XZ/2+X316+ = X(1
1
+ XI2 + X2/6+ . ..)
(3)
Equation 3 can now he used for any small value of X without loss of accuracy. I t should be noted that the method of reformulation used in this example is different from that
Present address: 19 Cheney Drive, Storrs, CT 06268. 72
Journal of Chemical Education
in the first example. Whereas in the first example an equivalent mathematical expression could he derived to obtain the correct values of the roots. a series reoresentation was invoked i n theserund example t o overrunle the computntional diftic~~ltv. 'l'his shou,s that thrrr are many. wass - to mnnlpulate a mathematical expression to obtain maximum accuracy. There are many functions amenable to series expansion. These include (9)trigonometric functions such as SIN, COS, TAN, etc., and other functions such as LOG, LN, ERF, etc. Finally, consider a simple problem of the calculation of the standard deviation of a set of data. There are several equivalent mathematical expressions available to calculate the standard deviation and a particular manufacturer of calculator or comnuter mav"emolov . one exoression while the other may employ adifferent one.-~uffanbCarter (10) used several different types of calculators to calculate the standard deviation of a given set of data. They found different results on different calculators. Also, Solhera (11) evaluated the performance of various expremions f i r the calculation of standard deviation on different computers, again obtaining different results. The apparent inconsistencies in the final results can he traced to the method of representation of the numhers in the computer. In conclusion, it is important to realize the subtlety of the computation and to note that computers have some limitations. It is better to teach students of this fact early in their education. Instructors can reoroduce the examnles discussed here, even on a calculator, to impress upon the students the importance of learning the fundamental principles of mathematics and subtle points of computation. Students, finallv. must be reminded the dictum ~ h r a s e dbv Hammina (71, he purpose of computing is insight, not n&bers." Acknowledgment This work was partially supported by US. PHS Grant No. ES03154 awarded by the National Institute of Environmental Health Sciences and partially by the University of Connecticut Research Foundation.
Analog Signals for Digitization from Spectrophotometers with Special Emphasis on a Cary 14 Donald E. Jones Western Maryland College Westminster. MD 21 157 I t is often desirable to interface spectrophotometers or other equipment to a computer for the purposes of performing any of several mathematical or graphing operations on the sienals from the instrument. These instruments mav not have simple analog signals which can he hooked to the analog-to-digital converter directly. One example of this is the signal from any of a number of the older spectrophotometers which were designed and built before the advent of microcomputers. Since these instruments are still very serviceable the problem is how to interface them to computers. These instruments are multiplexed with respect to the signals from the photomultiplier. I t is as a result a very difficult software problem to sortthese several signals for data acquisition. Our solution is to deal only with the recorder and ignore the signals from the photomultiplier. The procedure described can he adapted to any gear-driven recorder whose input signals are not directly usable. We applied it to our Cary 14. We have mounted a 10-K, 10-turn, precision potentiometer on a locally made z hracket. A brass gear with proper tooth size and number is mounted on the potentiometer shaft and engages the pen drive gear. The hracket with the potentiometer and gear is then mounted on the rear of the Cary 14 recorder frame using suitably drilled and tapped