powered by

NUMERICAL ANALYSIS USING SCILAB:
NUMERICAL STABILITY AND CONDITIONING
In this Scilab tutorial we provide a collection of implemented examples onnumerical stability and conditioning.
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 tutorial is to provide a collection of Scilab examples
that are typically part of numerical analysis courses.
Here we provide some classical examples on numerical stability andconditioning.

An introduction toNUMERICAL ANALYSIS USING SCILAB(numerical stability and conditioning)

Step 2: Roadmap
In this tutorial we provide the definitions of well-conditioned problem andstable algorithm and some related examples. These examples are usefulto understand how much attention we have to pay when selecting a
numerical solution method for a given problem.

Numerical stability and conditionwww.openeering.com

Descriptions
Condition of problems
Condition examples
Stability of algorithms
Stability example
Conclusions and remarks

Steps
3
4-6
7
8-11
12-13

page 2/12

Step 3: Conditioning of a problem
Numerical stability and conditioning are two concepts that should not beconfused.

A problem is called well-conditioned if a small perturbation of the input
data (relative error), leads to small variations of the results (relative error),i.e. of the same magnitude order.
On the other hand, an ill-conditioned problem strongly amplifies the input
relative error in the output dataset.
Denoting by the problem under consideration, if represents the input
data andthe output results, it is possible to define the condition
number of the problem through the following inequality:‖ ‖‖ ‖( )‖ ‖‖ ‖

where ‖ ‖ is a given norm which is able to measure the involved
quantities. The condition number bounds the propagation of the input
relative error in the output results, it is closely related to the maximum
accuracy that can be attained in the solution. Wheneveror,
the condition number is defined as‖‖( ) ‖The numerical solution strategy should take into account the kind ofproblem we are trying to solve.

Numerical stability and condition

As an example, from the previous tutorial we have the following inequality:| || |()( )( ))()(||||(That is:‖.

Conditioning refers to the numerical problem and there is no connection
with the rounding error and the solution strategy.

A graphical comparison is shown on the right.

(Well-conditioned versus ill-conditioned problem)){}( ( )

( ))where we have defined| |
is the condition number relative to the input ;
||


| ||

|

is the condition number relative to the input y.

From this inequality, when
the condition numbers
andgrows
up to infinity and hence the relative error on the result can be arbitrarily huge.

www.openeering.com

page 3/12

Step 4: Example: Intersection of two straight lines
In this example we consider the intersection of two straight lines
given by the equations:andandThe intersection point is (). Now, if we change the coefficient of thesecond straight line fromto, the new solution becomes().
If we analyze the relative error of the system, we can see that the input‖ ‖||relative error is approximately ‖ ‖, while the| |relative errors on the solution are
for the variableandfor respectively. These values can be considered too highwhen compared to the order of magnitude of the input error. This is due tothe fact that the two straight lines
andare almost parallel (illconditioned).

Now, let’s consider the system whereto the line ,(Example of an ill-conditioned problem)

is replaced by the orthogonal line.

Using the previous perturbation, the solution now moves from () to(). In this case we have the same relative input error, but
the relative errors on the solution are
for the variable andfor , which can be considered small (same order ofmagnitude of the input). This is due to the fact that the two straight lines
and are almost orthogonal (well-conditioned).

(Example of a well-conditioned problem)

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

Numerical stability and conditionwww.openeering.com

page 4/12

Step 5: Zeros of polynomials
In this example we consider the problem of finding the real zeros of thepolynomial( )()()()()()()

and of ( ) and ( ), which are obtained changing the coefficient of
first withand then with.

As we may notice in the figure on the right, inare moved from real to imaginary.

( ) and( ) some roots

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

(Example of stability for zeros of a polynomial)(Roots of the three polynomials)

Numerical stability and conditionwww.openeering.com

page 5/12

Step 6: Exercise #1
Let’s consider the following polynomial( )which has 7 unitary roots for().

Plot, in a complex plane, the roots of( ) for different values of .

Hint: Use the Scilab function logspace to distribute the value of in a log-8space subdivision between 10 and 1. The function logspace(d1,d2, [n])d1d2
distributes n points between 10 and 10 .

(Results on roots perturbation with-8

varying in [10 ,1] )The Scilab script with the solution is reported in the function ex1.sce.

Numerical stability and conditionwww.openeering.com

page 6/12

Step 7: Numerical stability
To solve a given problem we use a certain algorithm and its numerical
implementation. Sometimes many algebraically equivalent solution
strategies are available, but numerically they can lead to different results.
This is due to computer’s arithmetic, which can propagate errors in a moreor less relevant way (see the Openeering tutorial on numerical errors).

Algorithms that do not magnify these errors are said to be numericallystable.

On the other hand, if an algorithm is numerically unstable, at a givenpoint, the errors do not remain bounded and tend to grow up in an
uncontrolled way corrupting completely the final result.

Hence, even when a problem is well-conditioned, if we try to solve it withan unstable algorithm, the obtained results will be meaningless.

(Stable and unstable algorithm with respect to a solution obtainedusing an exact analytical procedure with an infinite number of digits)

The following examples refer to a comparison between stable andunstable algorithms for two given problems.

Numerical stability and conditionwww.openeering.com

page 7/12

Step 8: Example of integral computation
In the next two steps, we compare two algorithms solving the following
integral:∫()Both algorithms are based on the following theoretical considerations:
∫

;

;

(the integrand)

Numerical stability and conditionwww.openeering.com

page 8/12

Step 9: Example of integral computation (unstableformulation)
The first strategy is to develop an algorithm based on the following
recursive formula:For

we have:(∫For);

we can used integration by parts having[(∫]∫

The developed program starts from), where.

To perform the error analysis we denote by
the approximate
value of the integral at stepwith respect to the exact value
andmaking an error . Hence, it is possible to write the following recursive
formula for the error
(and)

()

, with respect to the first error(As a consequence, even iffactorial.

), is(Absolute value of))is small, the error

Numerical stability and condition(grows up to infinity as awww.openeering.com

page 9/12

Step 10: Example of integral computation (stableformulation)
The second strategy is to develop an algorithm based on the following
recursive formula:For

we set:;For
we rewrite the previous recursive formulain terms ofas follows:()

The developed program starts fromintegral.

and computes

as the last

To perform the error analysis we denote by
the approximatevalue of the integral at stepwith respect to the exact value
andmaking an error . Hence, it is possible to write the following recursive
formula for the error(giving. Hence)()()

can be expressed in terms of(. The code for this plot is in intdemo.sce))

As a consequence, even if
is “big”, the error
we have a factorial as denominator.

Numerical stability and condition(Value ofasdecreases to zero, sincewww.openeering.com

page 10/12

Step 11: Exercise #2
Considering the stable formulation, plot the relative error forfromfor different values of in the range [].
The relative error on||||wherestarting

is computed asdepends on

and.

(Relative error of the approximation of depending on . Note that thevalues are visible only until N=17, after that limit the values are lessthen %eps and are not visible in a logarithmic scale)

Numerical stability and conditionwww.openeering.com

page 11/12

Step 12: 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 stability.

2. Openeering: www.openeering.com.

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

4. Atkinson, An Introduction to Numerical Analysis, Wiley

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

-------------Main directory-------------stabline.sce
stabpoly.sce
intdemo.sce
ex1.sceex2.scelicense.txt: Stability for line intersection: Stability for polynomial: Integral computation example: Solution of exercise #1: Solution of exercise #2: The license fileThank you for your attention,
Silvia Poles and Manolo Venturin

Numerical stability and conditionwww.openeering.com

page 12/12