Nash - Scientific Computing with PCs (523165), страница 58
Текст из файла (страница 58)
Fortunately powerful yet inexpensive language translators areavailable for the principal programming languages. Since many PCs are never used as programdevelopment environments, we may not find programming tools installed on the PC we are going to useto solve our problem. While Microsoft supplies an interpreter for BASIC with MS-DOS version 5 (calledQBASIC), no manual is supplied for this in versions we have seen.
Previous versions of MS-DOS (e.g.,version 4.01) were accompanied by the GWBASIC interpreter plus a manual for this version of theMicrosoft BASIC programming language. The interpreter, as we have seen in the timed Chapter 16, givesslow run times when compared to equivalent compilers.For those users with the luxury of a choice of solution tools, the following set of questions are pertinentto the selection:•What computational features of a programming language does the problem at hand require?·Floating-point or integer variables;·Precision of computation and range of exponents;·Maximum array size and maximum dimensionality (number of subscripts allowed);·Speed of computation.•Do we have subroutines, functions, macros or command scripts already available to us that can saveeffort if they are usable? If so, from what computing environments can we use these tools? Forexample, we may be able to call subroutines written in one language from other programminglanguages that provide better file management of input/output features.•Can we efficiently make use of the candidate solution software? That is, if we have chosen to use aspreadsheet package and need to write macros, can we do this without difficulty and delay? If wehave decided to program our method in Pascal, do we know how to effectively use the compiler athand, for example, in controlling options such as floating-point arithmetic and memory models?Clearly it is wise, where possible, to choose a method for which an algorithm is available.
That is, we havea recipe for using a particular method in our possession. If we are lucky, this has already beenprogrammed and exists in machine readable form. It may even have been implemented and tested, aconsiderable saving of time and effort to us. We usually find programs that take at least several hours toimplement unless unusual care has been taken to ease this task for the user.20: YOUR OWN STRATEGY177When an algorithm is already available, we enjoy many advantages compared to the situation where onlya reference is known.First, the properties of the algorithm are presumably better known, if not by the user himself, at least byother users. Thus, some knowledge of the features, advantages or pitfalls of an algorithm, or at least animplementation of an algorithm, can be determined from experience, available documentation or otherusers.If the algorithm has been implemented by the user on his or her own PC, then there is a reasonablechance that the method is quite well understood.
Many methods require a good comprehension of theirworkings to use them successfully. To attempt, for example, the blind use of a quadrature program forintegrating a function with singularities is foolhardy unless it is specifically designed to handle suchdifficulties. Equally, for smooth functions, it is overkill to use a highly sophisticated adaptive quadraturemethod; a simple method is sufficient. One may also want to check tables of integrals to see if analyticsolutions have been devised, in which case quadrature may be unnecessary.If a method is "available" we also need to ensure that it fits the task.
The Hooke and Jeeves functionminimization uses very little working storage and has an extremely low requirement for memory to storeprogram code. Nevertheless, it is very poorly suited to problems with large numbers of parameters dueto the number of function evaluations occasioned by each axial search step.
Thus, even if the Hooke andJeeves method fits the memory size requirements for minimizing a function of many parameters, it cannotbe said to "fit" the task overall, which must always presume a modicum of efficiency.The method chosen must fit the PC on which computations will be done. This goes beyond the questionof program and working storage. We must also consider the precision and speed of calculation, as wellas the capacity of peripherals to store or transmit data at the required rate or to present it in a suitableformat.Finally, we should be comfortable in using the method. This may seem incongruous, since users areprimarily interested in a solution rather than the route by which it is obtained. However, many problemsare sufficiently difficult that there is a real chance that methods may fail to find a solution.
Therefore, itcan be important to understand the method sufficiently well to recognize, and if possible recover from,such failures. For example, in nonlinear least squares or function minimization calculations there may bea premature convergence to a false solution. By noting certain features of a tentative solution, the usermay restart the search for a solution and obtain a correct result. Such questions are quite separate frommatters of personal taste, that may also influence the choice of method.20.4 Add-ons, Extras and FlexibilityIn the best of all worlds, we could easily choose between computing platforms to select the mostappropriate system in which to perform our computations.
Furthermore, we could easily switch platformswithout a huge effort in porting data and software.The unkindness of the real world is such that few of us are prepared to switch machines frequently (seeSections 1-5, 2-6, and 11-8). Nevertheless, we may be prepared to change software within a given platformif this is easy to do. In this respect we urge users:•To get hardware with sufficient power or capability to accommodate alternative uses. This impliessufficient memory and disk space, good hard-copy output devices such as printers, and floppy diskdrives that can read several formats for diskettes. We also advise that there be several input/outputports for data transfer and pointing devices.•To acquire software that is common or popular for our day-to-day work.
This increases the likelihoodthat there is a colleague or associate using the software so that we can compare notes on "bugs" orfixes. For specialty work, one may be willing to try out esoterica. If it works, fine; if it does not, at178Copyright © 1984, 1994 J C & M M NashNash Information Services Inc., 1975 Bel Air Drive, Ottawa, ON K2C 0X1 CanadaSCIENTIFIC COMPUTING WITH PCsCopy for:Dr. Dobb’s Journalleast our bread-and-butter tasks can carry on as usual.Some users make the mistake of getting a portable machine when one is not appropriate. The possibility"I might like to take it home to do some work" overpowers the flexibility of a system with slots for add-incircuit boards, a larger and more colorful display and a full size keyboard. There are good applicationsfor portable machines, but the flexibility of a desktop or tower unit is generally greater even if its mobilityis restricted.
For scientific users, we note that numeric co-processors are generally power-hungry and havebeen only rarely provided on portable machines, even as an option.We think it is wise to avoid unnecessary extras such as games, utility programs we will not use, graphicalcuriosities, or noise makers.Games distract from technical computing, they clutter the fixed disk and are common vectors of computervirus infections.
We believe games should usually be kept off PCs used for technical computing exceptfor those games used or being developed in the pursuit of educational goals. Games traded informallymay be a vehicle for computer viruses.PCs are often supplied with some interesting but inexpensive utility software. It is probably worth tryingit out, but we recommend deletion or archiving of such software unless it is used regularly, as it will tendto get in the way of useful programs. We have noted that some programs have similar or identical names— a definite source of trouble.The capability of laser printers and other high-resolution raster graphic devices to produce interestingprint or display fonts and icons has led to a growing tendency for people to play with such capabilities.Rarely is this productive of research.
Worse, graphics chew disk space and memory much faster thanprograms or scientific data. Moreover, when one really wants to prepare a display for a publication orpresentation, it is necessary to wade through much unwanted material to find the useful fonts or designs.Programs that make interesting sounds or "talk" using the standard loudspeaker of most PCs are pleasanttoys. For the handicapped, there are proper versions of such tools, For the rest of us, leave them alone.On the Macintosh, we have observed some users changing the "attention" sound (usually beeps onMS-DOS machines) to duck quacks, breaking glass, or thunder noises.The choice of method and algorithm for a given problem may be highly sensitive to goals ancillary orsubsidiary to the solution itself.
There may be concerns about the time required to obtain a solution, theavailability of diagnostic checks of the method, the tests we can apply to the solution, additionalinformation about the problem revealed by the method, or approximations or refinements of the solution.Some examples may help to highlight these ideas. In tasks where the solution must be obtained withina specified time, such as control of industrial processes, it makes sense to disregard methods that are quiteslow in computing answers, even if they offer other significant benefits.
Where speed is not essential, weare better off to choose reliability. In linear least squares approximation, for example, we have preferredto use the singular value decomposition so we can know the extent of multicollinearity in our predictingdata, although the svd is "slow" compared to other methods. Some methods provide information aboutthe quality of solution as we proceed. Many quadrature methods and differential equation integratorsprovide an estimate of errors made in the approximations used.
If such estimates are smaller than theaccuracy required in our particular calculation there is no need for us to refine the results further.We think the most useful extras for computational methods test the solution for correctness. (Thenumerical integration methods generally only provide error estimates, not error bounds.) Knowing thatan answer is right gives great peace of mind, even if the answer is only for a subproblem.Unfortunately, the specific data produced by a method and the format of its presentation are features thatmay outweigh all other considerations. If a particular layout of data is not generated, users or clients mayreject a program based on a method of proven reliability in favor of less trustworthy software with a morefamiliar layout.