SlideShare a Scribd company logo
1 of 12
Download to read offline
www.openeering.com
powered by
NUMERICAL ANALYSIS USING SCILAB:
NUMERICAL STABILITY AND CONDITIONING
In this Scilab tutorial we provide a collection of implemented examples on
numerical stability and conditioning.
Level
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Numerical stability and condition www.openeering.com page 2/12
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 and
conditioning.
An introduction to
NUMERICAL ANALYSIS USING SCILAB
(numerical stability and conditioning)
Step 2: Roadmap
In this tutorial we provide the definitions of well-conditioned problem and
stable algorithm and some related examples. These examples are useful
to understand how much attention we have to pay when selecting a
numerical solution method for a given problem.
Descriptions Steps
Condition of problems 3
Condition examples 4-6
Stability of algorithms 7
Stability example 8-11
Conclusions and remarks 12-13
Numerical stability and condition www.openeering.com page 3/12
Step 3: Conditioning of a problem
Numerical stability and conditioning are two concepts that should not be
confused.
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 and the 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. Whenever or ,
the condition number is defined as
‖ ‖ ( ) ‖ ‖.
Conditioning refers to the numerical problem and there is no connection
with the rounding error and the solution strategy.
The numerical solution strategy should take into account the kind of
problem we are trying to solve.
A graphical comparison is shown on the right.
(Well-conditioned versus ill-conditioned problem)
As an example, from the previous tutorial we have the following inequality:
( ) ( ) (
| |
| |
( )
| |
| |
( ))
That is: ( ) { } ( ( ) ( ))
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 and grows
up to infinity and hence the relative error on the result can be arbitrarily huge.
Numerical stability and condition www.openeering.com page 4/12
Step 4: Example: Intersection of two straight lines
In this example we consider the intersection of two straight lines and
given by the equations:
and
The intersection point is ( ). Now, if we change the coefficient of the
second straight line from to , 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 variable and
for respectively. These values can be considered too high
when compared to the order of magnitude of the input error. This is due to
the fact that the two straight lines and are almost parallel (ill-
conditioned).
Now, let’s consider the system where is replaced by the orthogonal line
to the 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 and
for , which can be considered small (same order of
magnitude of the input). This is due to the fact that the two straight lines
and are almost orthogonal (well-conditioned).
The Scilab script is reported in the function stabline.sce.
(Example of an ill-conditioned problem)
(Example of a well-conditioned problem)
Numerical stability and condition www.openeering.com page 5/12
Step 5: Zeros of polynomials
In this example we consider the problem of finding the real zeros of the
polynomial
( ) ( )( )( )( )( )( )
and of ( ) and ( ), which are obtained changing the coefficient of
first with and then with .
As we may notice in the figure on the right, in ( ) and ( ) some roots
are moved from real to imaginary.
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 condition www.openeering.com page 6/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
space subdivision between 10
-8
and 1. The function logspace(d1,d2, [n])
distributes n points between 10
d1
and 10
d2
.
The Scilab script with the solution is reported in the function ex1.sce.
(Results on roots perturbation with varying in [10
-8
,1] )
Numerical stability and condition www.openeering.com page 7/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 more
or less relevant way (see the Openeering tutorial on numerical errors).
Algorithms that do not magnify these errors are said to be numerically
stable.
On the other hand, if an algorithm is numerically unstable, at a given
point, 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 with
an unstable algorithm, the obtained results will be meaningless.
The following examples refer to a comparison between stable and
unstable algorithms for two given problems.
(Stable and unstable algorithm with respect to a solution obtained
using an exact analytical procedure with an infinite number of digits)
Numerical stability and condition www.openeering.com page 8/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 condition www.openeering.com page 9/12
Step 9: Example of integral computation (unstable
formulation)
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 step with respect to the exact value and
making an error . Hence, it is possible to write the following recursive
formula for the error
( ) ( ) ( )
and , with respect to the first error , is
( )
As a consequence, even if is small, the error grows up to infinity as a
factorial.
(Absolute value of )
Numerical stability and condition www.openeering.com page 10/12
Step 10: Example of integral computation (stable
formulation)
The second strategy is to develop an algorithm based on the following
recursive formula:
 For we set:
;
 For we rewrite the previous recursive formula
in terms of as follows:
( )
The developed program starts from and computes as the last
integral.
To perform the error analysis we denote by the approximate
value of the integral at step with respect to the exact value and
making an error . Hence, it is possible to write the following recursive
formula for the error
( ) ( ) ( )
giving . Hence can be expressed in terms of as
( )
As a consequence, even if is “big”, the error decreases to zero, since
we have a factorial as denominator.
(Value of . The code for this plot is in intdemo.sce)
Numerical stability and condition www.openeering.com page 11/12
Step 11: Exercise #2
Considering the stable formulation, plot the relative error for starting
from for different values of in the range [ ].
The relative error on is computed as
| |
| |
where depends on and .
(Relative error of the approximation of depending on . Note that the
values are visible only until N=17, after that limit the values are less
then %eps and are not visible in a logarithmic scale)
Numerical stability and condition www.openeering.com page 12/12
Step 12: Concluding remarks and References
In this tutorial we have collected a series of numerical examples written in
Scilab for the study of numerical stability.
1. Scilab Web Page: Available: www.scilab.org.
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.
Thank you for your attention,
Silvia Poles and Manolo Venturin
--------------
Main directory
--------------
stabline.sce : Stability for line intersection
stabpoly.sce : Stability for polynomial
intdemo.sce : Integral computation example
ex1.sce : Solution of exercise #1
ex2.sce : Solution of exercise #2
license.txt : The license file

More Related Content

What's hot

Solving systems of Linear Equations
Solving systems of Linear EquationsSolving systems of Linear Equations
Solving systems of Linear Equations
swartzje
 
Linear Equations and Inequalities in One Variable
Linear Equations and Inequalities in One VariableLinear Equations and Inequalities in One Variable
Linear Equations and Inequalities in One Variable
misey_margarette
 
7.7 Solving Radical Equations
7.7 Solving Radical Equations7.7 Solving Radical Equations
7.7 Solving Radical Equations
swartzje
 
Arithmetic Sequence and Series
Arithmetic Sequence and SeriesArithmetic Sequence and Series
Arithmetic Sequence and Series
itutor
 

What's hot (20)

Arithmetic Sequence
Arithmetic SequenceArithmetic Sequence
Arithmetic Sequence
 
GRADE 10 ARITHMETIC.pptx
GRADE 10 ARITHMETIC.pptxGRADE 10 ARITHMETIC.pptx
GRADE 10 ARITHMETIC.pptx
 
Lesson 1: Special Products
Lesson 1: Special ProductsLesson 1: Special Products
Lesson 1: Special Products
 
Mathematical modelling ppt
Mathematical modelling pptMathematical modelling ppt
Mathematical modelling ppt
 
Solving systems of Linear Equations
Solving systems of Linear EquationsSolving systems of Linear Equations
Solving systems of Linear Equations
 
Abstract algebra & its applications
Abstract algebra & its applicationsAbstract algebra & its applications
Abstract algebra & its applications
 
5As Method of Lesson Plan on Ssolving systems of linear equations in two vari...
5As Method of Lesson Plan on Ssolving systems of linear equations in two vari...5As Method of Lesson Plan on Ssolving systems of linear equations in two vari...
5As Method of Lesson Plan on Ssolving systems of linear equations in two vari...
 
Operations of-scientific-notation (Kyle Balais)
Operations of-scientific-notation (Kyle Balais)Operations of-scientific-notation (Kyle Balais)
Operations of-scientific-notation (Kyle Balais)
 
Linear Equations and Inequalities in One Variable
Linear Equations and Inequalities in One VariableLinear Equations and Inequalities in One Variable
Linear Equations and Inequalities in One Variable
 
QUADRATIC FUNCTIONS
QUADRATIC FUNCTIONSQUADRATIC FUNCTIONS
QUADRATIC FUNCTIONS
 
Solving Systems by Substitution
Solving Systems by SubstitutionSolving Systems by Substitution
Solving Systems by Substitution
 
7.7 Solving Radical Equations
7.7 Solving Radical Equations7.7 Solving Radical Equations
7.7 Solving Radical Equations
 
A presentation on differencial calculus
A presentation on differencial calculusA presentation on differencial calculus
A presentation on differencial calculus
 
Arithmetic Sequence and Series
Arithmetic Sequence and SeriesArithmetic Sequence and Series
Arithmetic Sequence and Series
 
Summation Notation
Summation NotationSummation Notation
Summation Notation
 
linear transformation
linear transformationlinear transformation
linear transformation
 
Transformation geometry
Transformation geometryTransformation geometry
Transformation geometry
 
Patterns, sequences and series
Patterns, sequences and seriesPatterns, sequences and series
Patterns, sequences and series
 
Integration of Trigonometric Functions
Integration of Trigonometric FunctionsIntegration of Trigonometric Functions
Integration of Trigonometric Functions
 
Absolute Value Equations and Inequalities
Absolute Value Equations and InequalitiesAbsolute Value Equations and Inequalities
Absolute Value Equations and Inequalities
 

Viewers also liked

Viewers also liked (10)

Numerical analysis using Scilab: Error analysis and propagation
Numerical analysis using Scilab: Error analysis and propagationNumerical analysis using Scilab: Error analysis and propagation
Numerical analysis using Scilab: Error analysis and propagation
 
Numerical analysis using Scilab: Solving nonlinear equations
Numerical analysis using Scilab: Solving nonlinear equationsNumerical analysis using Scilab: Solving nonlinear equations
Numerical analysis using Scilab: Solving nonlinear equations
 
First steps with Scilab
First steps with ScilabFirst steps with Scilab
First steps with Scilab
 
Scilab as a calculator
Scilab as a calculatorScilab as a calculator
Scilab as a calculator
 
Aeraulic toolbox for Xcos
Aeraulic toolbox for XcosAeraulic toolbox for Xcos
Aeraulic toolbox for Xcos
 
Data mining
Data miningData mining
Data mining
 
Modeling an ODE: 3 different approaches - Part 1
Modeling an ODE: 3 different approaches - Part 1Modeling an ODE: 3 different approaches - Part 1
Modeling an ODE: 3 different approaches - Part 1
 
Modeling an ODE: 3 different approaches - Part 2
Modeling an ODE: 3 different approaches - Part 2Modeling an ODE: 3 different approaches - Part 2
Modeling an ODE: 3 different approaches - Part 2
 
Introduction to Control systems in scilab
Introduction to Control systems in scilabIntroduction to Control systems in scilab
Introduction to Control systems in scilab
 
Introduction to Discrete Probabilities with Scilab - Michaël Baudin, Consort...
Introduction to Discrete Probabilities with Scilab - Michaël Baudin, Consort...Introduction to Discrete Probabilities with Scilab - Michaël Baudin, Consort...
Introduction to Discrete Probabilities with Scilab - Michaël Baudin, Consort...
 

Similar to Numerical analysis using Scilab: Numerical stability and conditioning

(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
Naoki Shibata
 
Simple lin regress_inference
Simple lin regress_inferenceSimple lin regress_inference
Simple lin regress_inference
Kemal İnciroğlu
 
Algorithm & data structure lec2
Algorithm & data structure lec2Algorithm & data structure lec2
Algorithm & data structure lec2
Abdul Khan
 

Similar to Numerical analysis using Scilab: Numerical stability and conditioning (20)

Chapter 18,19
Chapter 18,19Chapter 18,19
Chapter 18,19
 
Supervised Learning.pdf
Supervised Learning.pdfSupervised Learning.pdf
Supervised Learning.pdf
 
Algoritmos
AlgoritmosAlgoritmos
Algoritmos
 
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
 
Linear logisticregression
Linear logisticregressionLinear logisticregression
Linear logisticregression
 
working with python
working with pythonworking with python
working with python
 
A brief study on linear programming solving methods
A brief study on linear programming solving methodsA brief study on linear programming solving methods
A brief study on linear programming solving methods
 
Simple lin regress_inference
Simple lin regress_inferenceSimple lin regress_inference
Simple lin regress_inference
 
GENETIC ALGORITHM FOR FUNCTION APPROXIMATION: AN EXPERIMENTAL INVESTIGATION
GENETIC ALGORITHM FOR FUNCTION APPROXIMATION: AN EXPERIMENTAL INVESTIGATIONGENETIC ALGORITHM FOR FUNCTION APPROXIMATION: AN EXPERIMENTAL INVESTIGATION
GENETIC ALGORITHM FOR FUNCTION APPROXIMATION: AN EXPERIMENTAL INVESTIGATION
 
Machine learning session4(linear regression)
Machine learning   session4(linear regression)Machine learning   session4(linear regression)
Machine learning session4(linear regression)
 
Churn Analysis in Telecom Industry
Churn Analysis in Telecom IndustryChurn Analysis in Telecom Industry
Churn Analysis in Telecom Industry
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to Vectors
 
Curvefitting
CurvefittingCurvefitting
Curvefitting
 
Data Transformation
Data TransformationData Transformation
Data Transformation
 
Unger
UngerUnger
Unger
 
Algorithm & data structure lec2
Algorithm & data structure lec2Algorithm & data structure lec2
Algorithm & data structure lec2
 
PRML Chapter 7
PRML Chapter 7PRML Chapter 7
PRML Chapter 7
 
result analysis for deep leakage from gradients
result analysis for deep leakage from gradientsresult analysis for deep leakage from gradients
result analysis for deep leakage from gradients
 
03a control structures
03a   control structures03a   control structures
03a control structures
 

More from Scilab

More from Scilab (20)

Statistical Analysis for Robust Design
Statistical Analysis for Robust DesignStatistical Analysis for Robust Design
Statistical Analysis for Robust Design
 
Electric motor optimization
Electric motor optimizationElectric motor optimization
Electric motor optimization
 
Asteroidlanding - Scilab conference 2019 Keynote
Asteroidlanding - Scilab conference 2019 KeynoteAsteroidlanding - Scilab conference 2019 Keynote
Asteroidlanding - Scilab conference 2019 Keynote
 
Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...
Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...
Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...
 
Scilab and Xcos for Very Low Earth Orbits satellites modelling
Scilab and Xcos for Very Low Earth Orbits satellites modellingScilab and Xcos for Very Low Earth Orbits satellites modelling
Scilab and Xcos for Very Low Earth Orbits satellites modelling
 
X2C -a tool for model-based control development and automated code generation...
X2C -a tool for model-based control development and automated code generation...X2C -a tool for model-based control development and automated code generation...
X2C -a tool for model-based control development and automated code generation...
 
A Real-Time Interface for Xcos – an illustrative demonstration using a batter...
A Real-Time Interface for Xcos – an illustrative demonstration using a batter...A Real-Time Interface for Xcos – an illustrative demonstration using a batter...
A Real-Time Interface for Xcos – an illustrative demonstration using a batter...
 
Aircraft Simulation Model and Flight Control Laws Design Using Scilab and XCos
Aircraft Simulation Model and Flight Control Laws Design Using Scilab and XCosAircraft Simulation Model and Flight Control Laws Design Using Scilab and XCos
Aircraft Simulation Model and Flight Control Laws Design Using Scilab and XCos
 
Scilab for real dummies j.heikell - part3
Scilab for real dummies j.heikell - part3Scilab for real dummies j.heikell - part3
Scilab for real dummies j.heikell - part3
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
 
Scilab for real dummies j.heikell - part 1
Scilab for real dummies j.heikell - part 1Scilab for real dummies j.heikell - part 1
Scilab for real dummies j.heikell - part 1
 
Multiobjective optimization and Genetic algorithms in Scilab
Multiobjective optimization and Genetic algorithms in ScilabMultiobjective optimization and Genetic algorithms in Scilab
Multiobjective optimization and Genetic algorithms in Scilab
 
Scilab optimization workshop
Scilab optimization workshop Scilab optimization workshop
Scilab optimization workshop
 
INRA @ Scilab Conference 2018
INRA @ Scilab Conference 2018INRA @ Scilab Conference 2018
INRA @ Scilab Conference 2018
 
Qualcomm @ Scilab Conference 2018
Qualcomm @ Scilab Conference 2018Qualcomm @ Scilab Conference 2018
Qualcomm @ Scilab Conference 2018
 
Sanofi @ Scilab Conference 2018
Sanofi @ Scilab Conference 2018Sanofi @ Scilab Conference 2018
Sanofi @ Scilab Conference 2018
 
University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018
 
DLR @ Scilab Conference 2018
DLR @ Scilab Conference 2018DLR @ Scilab Conference 2018
DLR @ Scilab Conference 2018
 
Fraunhofer IIS @ Scilab Conference 2018
Fraunhofer IIS @ Scilab Conference 2018Fraunhofer IIS @ Scilab Conference 2018
Fraunhofer IIS @ Scilab Conference 2018
 
Arcelormittal @ Scilab Conference 2018
Arcelormittal @ Scilab Conference 2018Arcelormittal @ Scilab Conference 2018
Arcelormittal @ Scilab Conference 2018
 

Recently uploaded

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 

Numerical analysis using Scilab: Numerical stability and conditioning

  • 1. www.openeering.com powered by NUMERICAL ANALYSIS USING SCILAB: NUMERICAL STABILITY AND CONDITIONING In this Scilab tutorial we provide a collection of implemented examples on numerical stability and conditioning. Level This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
  • 2. Numerical stability and condition www.openeering.com page 2/12 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 and conditioning. An introduction to NUMERICAL ANALYSIS USING SCILAB (numerical stability and conditioning) Step 2: Roadmap In this tutorial we provide the definitions of well-conditioned problem and stable algorithm and some related examples. These examples are useful to understand how much attention we have to pay when selecting a numerical solution method for a given problem. Descriptions Steps Condition of problems 3 Condition examples 4-6 Stability of algorithms 7 Stability example 8-11 Conclusions and remarks 12-13
  • 3. Numerical stability and condition www.openeering.com page 3/12 Step 3: Conditioning of a problem Numerical stability and conditioning are two concepts that should not be confused. 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 and the 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. Whenever or , the condition number is defined as ‖ ‖ ( ) ‖ ‖. Conditioning refers to the numerical problem and there is no connection with the rounding error and the solution strategy. The numerical solution strategy should take into account the kind of problem we are trying to solve. A graphical comparison is shown on the right. (Well-conditioned versus ill-conditioned problem) As an example, from the previous tutorial we have the following inequality: ( ) ( ) ( | | | | ( ) | | | | ( )) That is: ( ) { } ( ( ) ( )) 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 and grows up to infinity and hence the relative error on the result can be arbitrarily huge.
  • 4. Numerical stability and condition www.openeering.com page 4/12 Step 4: Example: Intersection of two straight lines In this example we consider the intersection of two straight lines and given by the equations: and The intersection point is ( ). Now, if we change the coefficient of the second straight line from to , 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 variable and for respectively. These values can be considered too high when compared to the order of magnitude of the input error. This is due to the fact that the two straight lines and are almost parallel (ill- conditioned). Now, let’s consider the system where is replaced by the orthogonal line to the 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 and for , which can be considered small (same order of magnitude of the input). This is due to the fact that the two straight lines and are almost orthogonal (well-conditioned). The Scilab script is reported in the function stabline.sce. (Example of an ill-conditioned problem) (Example of a well-conditioned problem)
  • 5. Numerical stability and condition www.openeering.com page 5/12 Step 5: Zeros of polynomials In this example we consider the problem of finding the real zeros of the polynomial ( ) ( )( )( )( )( )( ) and of ( ) and ( ), which are obtained changing the coefficient of first with and then with . As we may notice in the figure on the right, in ( ) and ( ) some roots are moved from real to imaginary. The Scilab script is reported in the function stabpoly.sce. (Example of stability for zeros of a polynomial) (Roots of the three polynomials)
  • 6. Numerical stability and condition www.openeering.com page 6/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 space subdivision between 10 -8 and 1. The function logspace(d1,d2, [n]) distributes n points between 10 d1 and 10 d2 . The Scilab script with the solution is reported in the function ex1.sce. (Results on roots perturbation with varying in [10 -8 ,1] )
  • 7. Numerical stability and condition www.openeering.com page 7/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 more or less relevant way (see the Openeering tutorial on numerical errors). Algorithms that do not magnify these errors are said to be numerically stable. On the other hand, if an algorithm is numerically unstable, at a given point, 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 with an unstable algorithm, the obtained results will be meaningless. The following examples refer to a comparison between stable and unstable algorithms for two given problems. (Stable and unstable algorithm with respect to a solution obtained using an exact analytical procedure with an infinite number of digits)
  • 8. Numerical stability and condition www.openeering.com page 8/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)
  • 9. Numerical stability and condition www.openeering.com page 9/12 Step 9: Example of integral computation (unstable formulation) 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 step with respect to the exact value and making an error . Hence, it is possible to write the following recursive formula for the error ( ) ( ) ( ) and , with respect to the first error , is ( ) As a consequence, even if is small, the error grows up to infinity as a factorial. (Absolute value of )
  • 10. Numerical stability and condition www.openeering.com page 10/12 Step 10: Example of integral computation (stable formulation) The second strategy is to develop an algorithm based on the following recursive formula:  For we set: ;  For we rewrite the previous recursive formula in terms of as follows: ( ) The developed program starts from and computes as the last integral. To perform the error analysis we denote by the approximate value of the integral at step with respect to the exact value and making an error . Hence, it is possible to write the following recursive formula for the error ( ) ( ) ( ) giving . Hence can be expressed in terms of as ( ) As a consequence, even if is “big”, the error decreases to zero, since we have a factorial as denominator. (Value of . The code for this plot is in intdemo.sce)
  • 11. Numerical stability and condition www.openeering.com page 11/12 Step 11: Exercise #2 Considering the stable formulation, plot the relative error for starting from for different values of in the range [ ]. The relative error on is computed as | | | | where depends on and . (Relative error of the approximation of depending on . Note that the values are visible only until N=17, after that limit the values are less then %eps and are not visible in a logarithmic scale)
  • 12. Numerical stability and condition www.openeering.com page 12/12 Step 12: Concluding remarks and References In this tutorial we have collected a series of numerical examples written in Scilab for the study of numerical stability. 1. Scilab Web Page: Available: www.scilab.org. 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. Thank you for your attention, Silvia Poles and Manolo Venturin -------------- Main directory -------------- stabline.sce : Stability for line intersection stabpoly.sce : Stability for polynomial intdemo.sce : Integral computation example ex1.sce : Solution of exercise #1 ex2.sce : Solution of exercise #2 license.txt : The license file