powered by

NUMERICAL ANALYSIS USING SCILAB:
ERROR ANALYSIS AND PROPAGATIONThis tutorial provides a collection of numerical examples and advises on erroranalysis and its propagation. All examples are developed in Scilab.
Level

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

www.openeering.com

Step 1: The purpose of this tutorial
The purpose of this Scilab tutorial is to provide a collection of numericalexamples that are typically part of numerical analysis courses.
This tutorial is intended to help readers familiarize with numerical methods
and their implementations, keeping under control the error propagation.

An introduction toHere we provide some classical examples on error analysis andpropagation.

NUMERICAL ANALYSIS USING SCILAB(Error study in Numerical Analysis)

Step 2: Roadmap
In this tutorial, after a brief introduction to the concept of numerical errors,
we analyze some examples in which numerical errors occur. Theseexamples are useful to understand how important is to pay attention toerror propagation when implementing numerical methods.

Error analysis and propagationwww.openeering.com

Descriptions
Numerical errors
ExamplesConclusions and remarks

Steps
3-5
6-10
11-12

page 2/10

Step 3: Numerical error
What is allocated in a computer is only a subset of real number (usingIEEE 754 standard) and hence, a real number
is represented in thecomputer as, a fixed strings of digits. This limited amount of storage
introduces a rounding error (or round-off error). It is possible to prove thefollowing relation// Scilab command to obtain eps// ---------------------------%eps

with| |
whereis a constant that depends on the floating point system used torepresent the number (for double precision arithmetic
is equal to).

Step 4: Truncation error
The next step is to study what happens when the basic arithmetic
operations are used.
We denote the computer arithmetic as , ,from real arithmetic , , and respectively.

,to distinguish them

A part from the numerical error due to limited length in bits of registers, thecomputer arithmetic introduces a further truncation error when results aretransfer from CPU to the memory. This error is caused by the fact that thelength in bits of the CPU register is greater than the one used to store
numbers.

Error analysis and propagation

As an example, if we sum two numbers
the corresponding machine operation(and (to computecan be written as))|with |. The sum of two numbers involves the sum of thetwo floating point operands. Since this operation is done in a registerof the computer, it is necessary to consider a further floating point
representation when the number is transferred to be stored into thememory.

www.openeering.com

page 3/10

Example of cancellation error for subtraction operation

Step 5: Cancellation error
It is interesting to analyze the arithmetic operations when we consider
relative errors. For example, we want to analyze the sum operation:|||with. is the exponent (or characteristic) of the representation whileis the mantissa of the representation. The mantissa has always afixed number of digits, in this case m.

|

in terms of the relative error of the input operands
error for is defined as|

In this example we consider a decimal arithmetic with floating point where anumber is expressed in the following way:

and . The relative
For example, we can computeusing a system with a mantissa of
4 digits for the number, while we use a mantissa of 8 digits for the internal
representations in the CPU register.

|| |The example is done using
A computer operation

whereandandFrom memory to registers:
Memory (mantissa = 4)

is considered numerically stable when

It is possible to prove that the computer operations
andare the only
stable operations with respect to the rounding error. Conversely, foraddition we have:
| |
|| |
|

Register (mantissa = 8)
are two input operands.

(.

||)

Arithmetic operation with alignment of the exponent:
Register (mantissa = 8)
Register with aligned exp.
+
From register to memory:
Register (mantissa = 8)

Memory (mantissa = 4)
A similar inequality holds for subtraction.

When, the right hand side of the inequality may be very high andhence may generate a high relative error (cancellation error).

It is easy to compute the final step in which we subtract again 1 to evaluate. As a result we obtainthat is not equal to x.

Cancellation error should be avoided whenever possible!

Error analysis and propagationwww.openeering.com

page 4/10

Step 6: Two equivalent expressions
In this example we compare the following two equivalent expressions:

These two expressions are equivalent from an algebraic point of view; thesecond expression is simply obtained from the first one throughsimplification.

The first function suffers of the cancellation error when goes to zero.
This phenomenon has been explained in the previous step.

In the reported figure we have plotted the error
may see that the cancellation error is huge when
phenomenon produces a loss of significant digits.

. We
is close to zero. This(Error err in the range [-1e-07;1e-07])

The Scilab script for the figure on the right is available in ex01.sce. The
code can be downloaded from the Openeering website.

Error analysis and propagationwww.openeering.com

page 5/10

Step 7: Two equivalent polynomials
In this example, we compare the two following polynomial expressions:where the first expression is obtained from the second by expansion.

As depicted on the right, the second expression is numerically stable while
the first one is more unstable.

(Comparison between two algebraic equivalent polynomials)

The Scilab script is reported in the function ex02.sce.

Error analysis and propagationwww.openeering.com

page 6/10

Step 8: Derivative example
In this step, we study the computation of a derivative from a numericalpoint of view. To approximate the first derivate, we use here the difference
quotient (a.k.a. Newton’s quotient):

For example, we may analyze the formula for the function
point
varying h in the following way:at

(Value of the derivative changing the value of h)
The plot on the right visualizes the results.

From a mathematical point of view, whengoes to zero, the formula
should assume the value of the first derivative. Intuitively, we may expect
the smaller the , the better the approximation. Unfortunately, because ofcancellation errors, it happens that the most reliable value for the derivate
is reached in(for, the value of the derivate is the sameas).

(Derivative example – table of results)
The Scilab script for plot and table is reported in the function ex03.sce.

Error analysis and propagationwww.openeering.compage 7/10

Step 9: Error analysis and optimal step

Evaluation of the round-off error:

The Newton’s quotient to approximate the derivative
sources of error:Round-off error;

Truncation error.

contains two

The round-off error for the Newton’s quotient can be written as:(|This follows from the Taylor series expansion of)|:and hence:

In order to evaluate this error, with
We do not know the signs ofwith ̅. This leads to:)where| |||where | |(remember that
Moreover we ignore error from division by .
where(small, we replace

and).

by, so we replace the difference

The first term contributes to round-off error, while the second term gives
rise to a truncation error.

̅||̅

As reported on the right the total error can be expressed aswhere||.

̅

From the above formula it is possible to compute the optimal step size .
Taking the derivative of the total error with respect to and setting thisquantity equal to zero, we have:√Evaluation of the truncation error:
The truncation error is given by:̅|
where for small values ofThis

represents the optimal value forError analysis and propagation

we replace|
byand|

to minimize the total error.

www.openeering.com

page 8/10|.

Step 10: Exercise
It is possible to compute the second derivatives of a function using thefollowing approximation

Apply the above formula to compute the second derivative of the function
at a given point.

(Relative error for second derivative approximation)

Moreover, prove the following estimate for the total error:|where()(|)()| and|The upper bound error is minimized when√|.

has the value̅

Hints: Using Taylor expansion for the function
the fourth order paying attention to the signs.

Error analysis and propagation̅|andtowww.openeering.com(Second derivative approximation, table of results)

page 9/10

Step 11: Concluding remarks and References
1. Scilab Web Page: Available: www.scilab.org.
In this tutorial we have collected a series of numerical examples written in
Scilab for the study of numerical errors.
2. Openeering: www.openeering.com.

3. J. Higham, accuracy and Stability of Numerical Algorithms, SIAM

4. Atkinson, An Introduction to Numerical Analysis, Wiley

Step 12: Software content
To report a bug or suggest improvements please contact Openeering
team at the web site www.openeering.com.

-------------Main directory-------------ex01.sce
ex02.sceex03.sceex04.scelicense.txt: Expression example: Polynomial example: Derivative example: Second derivative exercise: The license fileThank you for your attention,
Silvia Poles and Manolo Venturin

Error analysis and propagationwww.openeering.com

page 10/10