Numeric Computations in Java
Numerical computation is the study and devising of procedures, methods, and functions for solving problems with a computer. An algorithm is used in a systematic way that solves a problem. A numeric computation software developer is not just interested in computing the answer for a problem, but also the best or optimal algorithm that gets there in the most efficient way. The efficiency can be measured by the number of steps in the algorithm, CPU time, and the amount of memory allocated for a specific numerical computation. The advantage of numerical computation is that a numerical answer to a specific model problem can always be obtained even when it has no analytic solution at all. Take the following equation:
Arithmetic and Errors
Because numerical computation is compute intensive, and there are a lot of internal iterations for a specific algorithm, it is very important to set certain parameters at the correct level. If the tolerance level is set too small, it will consume a lot of memory or create an infinite loop. When it is too high between search boundaries, the procedure will terminate early and miss the solution. The following pseudo-code illustrates this point. This is the algorithm for the bisection method, that solves the roots of a function with one independent variable z, that is f(z):
DO c = (a + b)/2 IF( f(c)*f(a) < 0) b = c ELSE a = c WHILE ( |a-b| < 2*TOL )
The bisection method searches for the root in an interval section (boundaries) between z=a and z=b for a value of z where f(z)=0, the value z=c. is a root solution to f(z) with an error of no more than ½ |a-b|. A reasonable value of the tolerance (TOL) is 1.0E-3 , and it should not be much less than, say, 1.0E-5 or the problem will be too slow to converge to the solution. Sometimes tolerance value depends on the type of problem to be solved. For example, if you are developing software for nuclear physics analysis, you must set the tolerance to a smaller value that is to be less than the atomic or nucleon radius which is around the order of 1.0E-9 to 1.0E-15 meters; if you do not do this, your software will never find any solution (roots).
In numerical computing, the software developer should always be looking for trade-offs and optimal parameter values so that computation is efficient. This always applies even though you are using the correct algorithm.
The following sections contain different types of common errors that arise in numerical computation; these originate from numerical analysis ways of implementation and also the inexact arithmetic of the computer:
This type of error is caused by the method of approximation by itself. A good example is the polynomial approximation of sin(x) by using the Taylor series. Let's say we approximate the first three terms (n=0,1,2):
Nevertheless, we do know by analytic form that to compute sin(x), it really requires an infinitely long series. The error arises because the series is truncated; it has nothing to do with the computer at all. The remaining summation represents the error. It is unavoidable, but the series must be truncated to enable any real problem or algorithm to be computable.
Computers always use floating-point numbers (real numbers) of a fixed word length and the exact or true value is not expressed precisely by such computer representations. When floating-point numbers are rounded and stored, the round-off error is smaller than if the trailing digits were simply lopped off.
Page 1 of 5