Page 45 - Applied Numerical Methods Using MATLAB
P. 45
34 MATLAB USAGE AND COMPUTATIONAL ERRORS
From this, we can see why the relative error is magnified to cause the “loss
of significance” in the case of subtraction when the two numbers X and Y are
almost equal so that |X − Y|≈ 0.
The magnitudes of the absolute and relative errors in the multiplication/division
are
|ε xy |=|XY − xy|= |XY − (X + ε x )(Y + ε y )|≈ |Xε y ± Yε x |
|ε xy |≤|X||ε y |+ |Y||ε x | (1.2.13)
|ε xy | |ε y | |ε x |
|ρ xy |= ≤ + =|ρ x |+ |ρ y | (1.2.14)
|XY| |Y| |X|
X X
x X + ε x |Xε y − Yε x |
|ε x/y |= − = − ≈
Y y Y Y + ε y Y
2
|X||ε y |+ |Y||ε x |
|ε x/y |≤ (1.2.15)
Y 2
|ε x/y | |ε x | |ε y |
|ρ x/y |= ≤ + =|ρ x |+ |ρ y | (1.2.16)
|X/Y| |X| |Y|
This implies that, in the worst case, the relative error in multiplication/division
may be as large as the sum of the relative errors of the two numbers.
1.2.5 Tips for Avoiding Large Errors
In this section we will look over several tips to reduce the chance of large errors
occurring in calculations.
First, in order to decrease the magnitude of round-off errors and to lower the
possibility of overflow/underflow errors, make the intermediate result as close to
1 as possible in consecutive multiplication/division processes. According to this
rule, when computing xy/z, we program the formula as
ž (xy)/z when x and y in the multiplication are very different in magnitude,
ž x(y/z) when y and z in the division are close in magnitude, and
ž (x/z)y when x and z in the division are close in magnitude.
n
For instance, when computing y /e nx with x 1and y 1, we would program
nx
n
x n
it as (y/e ) rather than as y /e , so that overflow/underflow can be avoided. You
may verify this by running the following MATLAB program “nm125_1.m”.
%nm125_1:
x = 36; y = 1e16;
for n = [-20 -19 19 20]
fprintf(’y^%2d/e^%2dx = %25.15e\n’,n,n,y^n/exp(n*x));
fprintf(’(y/e^x)^%2d = %25.15e\n’,n,(y/exp(x))^n);
end