Numerieke wiskunde (WISB251) Tristan van Leeuwen HFG 609
[email protected]
Week 1 - Hoofdstuk Hoofdst uk 1 & 2
Wiskundige modellen vind je overal: overal: - weersverwachtingen - klimaatmodellen - optimaliseren van productieprocessen - aansturen van processen - analyseren van data -…
Deze leiden tot uiteenlopende wiskundige vraagstukken: - (partiële) differentiaalvergelijkingen - niet lineare vergelijkingen - stelsels vergelijkingen - interpolatie - integralen
Meestal is de oplossing niet makkelijk uit te drukken
We moeten de oplossing numeriek benaderen aan de hand van een algoritme
Daarbij willen we weten: - Hoe goed is de benadering - Is het algoritme gevoelig voor verstoringen - Hoe efficient is het algoritme
In het begin van de 20e eeuw werden zulke numerieke berekeningen veelal met de hand gedaan
Vanaf de 2e wereldoorlog deden digitale computers hun intrede
Voor meer info, zie: http://history.siam.org/
Inhoud
- Afrondfouten (H1, H2) - Oplossen van (stelsels van) (niet-) lineare vergelijkingen (H3, H5) - Interpoleren (H10, H11) - Numeriek integreren en differentieren (H14, H15) - Numeriek oplosson van gewone differentiaalvergelijkingen (H16) Werkvormen
- hoorcollege, bereid je voor door de hoofdstukken te lezen - werkcollege, je gaat aan de slag met opgaven uit het boek - computerprakticum, je gaat met Matlab aan de slag om het geleerde in de praktijk te brengen. Let op! Je gebruikt je eigen laptop hiervoor! Beoordeling
- inleveropgaven (25 %) voor details zie blackboard onder Assignments - tentamen (35 %) - eindverslag (40 %) voor details zie blackboard onder Assignments
Meer informatie over de inhoud van het vak is te vinden op Blackboard
Numerical Algorithms Goals
Goals of this chapter
•
•
•
•
To explain what numerical algorithms are; to describe various sources and types of errors and how to measure them; to discuss algorithm properties and explain in a basic manner the notions of conditioning and stability; to illustrate the potentially damaging e ff ect of roundoff errors.
Numerical Algorithms Outline
Outline
•
•
•
Scientific computing Numerical algorithms and errors Algorithm properties
Numerical Algorithms
Scientific computing
Observed phenomenon
Mathematical model
Discretization
Efficiency
Accuracy
Solution algorithm
Robustness
Implementation
Programming environment
Data structures
Figure: Scientific
Computing architecture
computing.
Numerical Algorithms
Scientific computing
Observed phenomenon
Mathematical model
Discretization
Efficiency
Accuracy
Solution algorithm
Robustness
Implementation
Programming environment
Data structures
Figure: Scientific
Computing architecture
computing.
Numerical Algorithms
Numerical algorithms and errors
Outline
•
•
•
Scientific computing Numerical algorithms and errors Algorithm properties
Numerical Algorithms
Numerical algorithms and errors
How to measure errors
•
•
•
Can measure errors as absolute or relative, or a combination of both. The absolute error in v approximating u is |u − v |. |u − v | The relative error (assuming u ̸ = 0) is . |u| u
v
1 1 -1.5 100 100
0.99 1.01 -1.2 99.99 99
Absolute Error 0.01 0.01 0.3 0.01 1
Relative Error 0.01 0.01 0.2 0.0001 0.01
Numerical Algorithms
Numerical algorithms and errors
Source and type of errors
•
Errors in the problem to be solved • •
•
In the mathematical model (an approximation to reality) In input data
Approximation errors (in the numerical algorithm) • • •
Discretization errors Convergence errors Roundoff errors
Numerical Algorithms
Numerical algorithms and errors
Example
Given smooth function f (x), approximate derivative at some point x = x 0 : f (x0 + h) − f (x0 ) f (x0 ) ≈ , h ′
for a small parameter value h. Discretization error:
f (x ) − f (x + hh) − f (x ) ≈ h2 |f (x )| . ′
0
0
0
′′
0
Numerical Algorithms
Numerical algorithms and errors
Results
Try for f (x) = sin(x) at x0 = 1.2. (So we are approximating cos(1.2) = 0.362357754476674... .) h
0.1 0.01 0.001 1.e-4 1.e-7
Absolute error 4.716676e-2 4.666196e-3 4.660799e-4 4.660256e-5 4.619326e-8
These results reflect the discretization error as expected.
Numerical Algorithms
Numerical algorithms and errors
Results for smaller
h
Absolute error 1.e-8 4.361050e-10 1.e-9 5.594726e-8 1.e-10 1.669696e-7 1.e-11 7.938531e-6 1.e-13 6.851746e-4 1.e-15 8.173146e-2 1.e-16 3.623578e-1 h
These results reflect both discretization and roundoff errors.
Run program Example1 3Figure1 3.m
Numerical Algorithms
Numerical algorithms and errors
Results for all
h
0
10
!5
10 r o r r e e t u l o s b A
!10
10
!15
10
!20
10
!15
10
!10
10 h
!5
0
10
10
The solid curve interpolates the computed values of |f (x0 ) − f (x +hh) f (x ) | for f (x) = sin(x), x0 = 1.2. Shown in dash-dot style is a straight line depicting the discretization error without roundo ff error. ′
0
−
0
Numerical Algorithms
Algorithm properties
Outline
•
•
•
Scientific computing Numerical algorithms and errors Algorithm properties
Numerical Algorithms
Algorithm properties
Algorithm Properties
•
•
•
Accuracy Efficiency (surprisingly hard to measure) Robustness
Numerical Algorithms
Algorithm properties
Problem conditioning and algorithm stability
Qualitatively speaking : •
•
The problem is ill-conditioned if a small perturbation in the data may produce a large diff erence in the result. The problem is well-conditioned otherwise. The algorithm is stable if its output is the exact result of a slightly perturbed input.
Next, we’ll see how bad roundoff error accumulation can be when an unstable algorithm is used.
Numerical Algorithms
Algorithm properties
Unstable algorithm: an extreme example Problem statement: evaluate the integrals 1
yn =
0
xn x + 10
dx
for n = 1, 2, . . . , 30. Algorithm development: observe that analytically 1
yn + 10yn
−
1
=
0
xn + 10xn x + 10
1
1
−
dx =
x
n−1
0
Also 1
y0 =
0
1 dx = ln(11) − ln(10). x + 10
Algorithm: Evaluate y0 = ln(11) − ln(10). For n = 1, . . . , 30, evaluate yn = Run program Example1 6.m • •
1 n
− 10 yn
1.
−
dx =
1 n
.
10
10
t u o f e 10 0 t u l o s b A
10
-10
0
10
20
30
Numerical Algorithms
Algorithm properties
Roundoff error accumulation
•
In general, if E n is error after n elementary operations, cannot avoid linear roundoff error accumulation E n ≃ c0 nE 0 .
•
Will not tolerate an exponential error growth such as E n ≃ cn 1 E 0
for some constant
– an unstable algorithm.
c1 > 1