Download Computer errors in numerical methods

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

History of statistics wikipedia , lookup

Strähle construction wikipedia , lookup

Transcript
COMPUTER ERRORS IN NUMERICAL METHODS
Krešimir Malarić, Roman Malarić
Faculty of Electrical Engineering and Computing, Unska 3, HR-10000 Zagreb, Croatia,
e-mail [email protected], [email protected]
ABSTRACT: This work deals with computer errors such as round-off error and truncation error. It
points out possible errors and gives a method to avoid them. Errors' occurring when solving linear
equations and a possible solution for avoiding them is shown.
Keywords: computer error, numerical methods
1. INTRODUCTION
When dealing with numerical methods, certain imperfections of computers have to be taken into the
account. A certain problem that would take several days of counting, or impossible to do it properly,
can quite easily and quickly be done with a PC at disposal to almost anyone. However, PCs have
limitations, which have to be included into the consideration, and prior knowledge of these so-called
computer errors can improve our calculation a great deal.
2. BASIC COMPUTER ERRORS
2.1. Round-off error
First important error is round-off error. Example for this error is following: if we input a number with
more than 15 decimal digits into the computer (in Excell), the computer will not recognize it. The
number 0,1234567890123456 will be saved and read as 0,123456790123450 (round-off error). Over
the years, the computers have improved, for only couple of years ago, 9th digit was not recognized. In
the future, computers will be more efficient, and error will be smaller, but it will not disappear.
2.2. Truncation error
The next error is so-called truncation error. This error appears while attempting to approximate a
certain mathematical operation led by a computer program. It is presumed here that there is no roundoff error. If, for example, we calculate numerical derivation in some point according to the equation
D(h) =
where h converges to 0.
f( xo + h) - f( x o )
h
(1)
tangent
approximation
ja
tangente
f(x0+h)
f(x0)
tangent
h
x0
x0+h
Fig. 1. Derivative of a function
Table 1. Errors in numerical approximation of a derivative
h
exp(1)-D(h)
5,000000000000000E-01 -8,085326552989940E-01
1,250000000000000E-01 -1,771983352128430E-01
3,125000000000000E-02 -4,291906044276630E-02
7,812500000000000E-03 -1,064599427702320E-02
1,953125000000000E-03 -2,656301179353000E-03
4,882812500000000E-04 -6,637510524103440E-04
1,220703125000000E-04 -1,659175077963760E-04
3,051757812500000E-05 -4,147811439336730E-05
7,629394531250000E-06 -1,036945202370630E-05
1,907348632812500E-06 -2,592442864379760E-06
4,768371582031250E-07 -6,485398205136050E-07
1,192092895507810E-07 -1,633207591389410E-07
2,980232238769530E-08 -5,156205018508330E-08
7,450580596923830E-09 -3,666088899123570E-08
1,862645149230960E-09 -1,558701785420170E-07
4,656612873077390E-10 8,254840055954560E-08
1,164153218269350E-10 -2,778474548659200E-06
2,910383045673370E-11 -1,040786907990920E-05
7,275957614183430E-12 -4,092544720490920E-05
1,818989403545860E-12 2,010970904509080E-05
4,547473508864640E-13 -4,681715409549090E-04
1,136868377216160E-13 -4,681715409549090E-04
2,842170943040400E-14 -4,681715409549090E-04
7,105427357601000E-15 -3,171817154095490E-02
1,776356839400250E-15 -3,171817154095490E-02
4,440892098500630E-16 -2,817181715409550E-01
1,110223024625160E-16 2,718281828459050E+00
2,775557561562890E-17 2,718281828459050E+00
round-off error
dominates
truncation error
dominates
Log (abs(D(h)-exp(1)))
Fig. 1. represents tangent approximation. If h is “too large”, then D(h) becomes inaccurate because h.
is not sufficiently close to the limit. This error appears because we are trying to approximate an
unrealisable limiting operation, the derivative with “realisable” arithmetic formula D(h). This error
would occur even if f(x) and D (h) could be evaluated exactly. When h becomes very small, round-off
error starts to dominate. The round-off and truncation errors in computing f(xo+h)-f(xo) are large
relative to the actual value of this difference. Round-off error would not be present if D(h) could
somehow be computed perfectly. Table 1. show errors in numerical approximation of a derivative.
Other functions like tan, sqrt, etc. would
2
give similar results. Having in mind all
the objections mentioned above, one
0
might think that a computer has
-20
-15
-10
-5
0
limitations, but knowing them in advance,
-2
we might still make PC very useful tool.
-4
The accuracy of PC increases with new
models, but they will always have error,
Round-off error
-6
because they use strings of 0’s and 1’s of
dominates
uniform length. Fig. 2 shows error versus
-8
step size in logarithmic scale.
Log (h)
Truncation
error dominates
Fig 2. Error versus step size
3. SOLUTION OF LINEAR EQUATIONS
Linear equations have following form:
a11x1 + a12x2 + ... + a1nxn = b1
a21x1 + a22x2 + ... + a2nxn = b2
.
.
.
.
.
.
.
.
.
.
.
.
am1x1 + am2x2 + ... + amnxn = bm.
(2)
Coefficients aij and bi are real or complex numbers. The system of equations has m equations with n
unknowns x1, x2,..., xn. In many mathematical computations and numerical methods it is necessary to
solve this system of equations. In many cases the solution can be found with so-called “naive”
procedures, but sometimes, round-off error must be taken into consideration.
3.1. Naive Gaussian elimination
There are several variations of Gaussian elimination. With Gaussian elimination there is no truncation
error, as with other methods, only round-off error. General Gaussian elimination method is well
known and it will not be discussed here further. Due to the round-off error, naive Gaussian elimination
can sometimes be unsatisfactory. That will be shown in the following example. If it is assumed that we
did not have round-off errors in previous calculations, and that we came to the last two equations of
the system:
0xn-1 + xn = 1
2xn-1 + xn = 3,
where 0 is result from the previous calculation. The solution of the equation is xn = xn-1 = 1. However,
the true system of the equation is:
εxn-1 + xn = 1
2xn-1 + xn = 3,
Here ε represents a small value, which is the result of the round-off error. As ε0, the further
calculation is as follows:
εxn-1 + xn = 1
(1-2/ε)xn = 3 - 2/ε
which gives,
xn = (3-2/ε)/(1-2/ε),
xn-1 = (1-xn)/ε
For the values of ε close to 0, the values of 3-2/ε and 1-2/ε are very close to -2/ε, so the value of xn is
very close to 1, which is a true value. However, xn-1 = (1-xn)/ε will give nonsense, because 1-xn will be
under influence of the error calculated in xn, and even greater error will be made by ε in denominator,
which can have any value whatsoever. It can be seen that the calculation of other unknowns xn-2,..., x1,
based on the calculated xn-1 can only result in larger error. This method is unacceptable for the reason
of parameter placement. The problem in the previous calculation is not ε being small; the problem is
that ε is small compared to the other coefficients in the same column. This can be avoided if we
change the leading coefficient, replacing it with the largest in the same column (partial pivoting), or
with the largest in all remaining rows and columns (maximal pivoting).
3.2. Pivoting of the first coefficient
Partial pivoting
...
...
a11
a22(1)
a1n
a2n(1)
.
.
.
ak-1,n(k-2)
.
.
.
ak-1,k-1(k-2)
Search this portion
of kth column for
pivot
...
akk(k-1)
.
.
.
ank(k-1)
...
...
Maximum pivoting
...
...
a11
a22(1)
.
.
.
ak-1,k-1(k-2)
Search this portion of
matrix for pivot
...
akk(k-1)
.
.
.
ank(k-1)
...
...
akn(k-1)
.
.
.
ann(k-1)
(3)
a1n
a2n(1)
.
.
.
ak-1,n(k-2)
a kn(k-1)
.
.
.
ann(k-1)
(4)
In partial pivoting, the search is done in kth column, and with maximum pivoting, the search is done in
the whole remaining matrix. Partial pivoting is simpler, but the larger errors are also possible. Now, if
we will look at our problem again.
εxn-1 + xn = 1
2xn-1 + xn = 3,
Number 2 is largest and the new system will be:
2xn-1 + xn = 3
εxn-1 + xn = 1.
Further calculation will give as follows,
2xn-1 + xn = 3
(1-ε/2)xn = 1-3ε/2,
as ε is small, xn  1.0, and
xn-1 = (3-xn)/2  1.0
which gives accurate result.
4. CONCLUSION
Computer has two fundamental capabilities: a) it can store a finite set of numbers and b) it can perform
arithmetic operation (addition, subtraction, multiplication and division) and it can find whether x is
greater, equal or less than y. Examples of round-off error and truncation error was given, which have
to be considered in numerical computations with PC. Gaussian elimination with pivoting was shown,
and how it reduces the possibility of error.
5. BIBLIOGRAPHY
[1]
Sidney Yakowitz & Ferenc Szidarovszky, An Introduction to Numerical Computations,
Macmillan Publishing Company, New York, 1986
[2]
Josip Butorac, Krešimir Malarić: Program za računanje nepouzdanosti pri Gaussovoj
interpolaciji nelinearnih funkcija više varijabli – praktično mjeriteljsko pomagalo, Zbornik
radova “38. međunarodni godišnji skup KoREMA”, Zagreb, 26-28. travnja 1993., str. 264268
POGREŠKE RAČUNALA KOD NUMERIČKIH METODA
SAŽETAK: Ovaj rad se bavi pogreškama računala kao što su pogreška zokruživanja i skraćivanja.
Ukazuje na moguće greške i daje metodu kako ih izbjeći. Pokazane su pogreške koje nastaju kod
rješavanja linearnih jednadžbi i metoda kako se mogu izbjeći.
Ključne riječi: pogreška računala, numeričke metode