Professional Documents
Culture Documents
References
Excellent reference.
Matlab help
2n
n
e
n
is used to approximate u = n! = 1 2 n for large n.
The formula involves the constant e = exp(1) = 2.7182818 . . ..
We use the Matlab program Example1 1.m from
http://www.siam.org/books/cs07/programs.zip
to compute the values of u and v for n = 1, . . . , 10.
Notice that the quality of v approximating u increases although
the absolute error increases rapidly!
NumCSE, Lecture 1, Sept 19, 2013 19/40
Numerical Methods for Computational Science and Engineering
Numerical algorithms and errors
Types of errors
Approximation errors
Discretization error.
Roundo errors
(x
0
) of a given
smooth function f (x) at the point x = x
0
.
Example: Let f (x) = sin(x), < x < , and set x
0
= 1.2.
Thus, f (x
0
) = sin(1.2) 0.932 . . ..
Discretization: Function values f (x) are available only at a discrete
number of points, e.g. at grid points x
j
= x
0
+ jh, j Z.
Want to approximate f
(x
0
) by values f (x
j
).
NumCSE, Lecture 1, Sept 19, 2013 21/40
Numerical Methods for Computational Science and Engineering
Numerical algorithms and errors
Discretization errors in action (cont.)
Taylors series gives us an algorithm to approximate f
(x
0
):
f
(x
0
) D
x
0
,h
(f ) =
f (x
0
+ h) f (x
0
)
h
NumCSE, Lecture 1, Sept 19, 2013 22/40
Numerical Methods for Computational Science and Engineering
Numerical algorithms and errors
Discretization errors in action (cont.)
Expanding f (x) by a Taylor series around x = x
0
gives
f (x
0
+ h) f (x
0
)
h
= f
(x
0
)
h
2
f
(), x
0
< < x
0
+ h.
So, we expect the error to decrease linearly with h.
(x
0
)
f (x
0
+ h) f (x
0
)
h
=
h
2
()
h
2
(x
0
)
(x
0
) D
x
0
,h
(f )
= O(h).
NumCSE, Lecture 1, Sept 19, 2013 23/40
Numerical Methods for Computational Science and Engineering
Numerical algorithms and errors
Results
Try for f (x) = sin(x) at x
0
= 1.2.
(So, we are approximating cos(1.2) = 0.362357754476674 . . .)
h Absolute error
0.1 4.71667 10
2
0.01 4.666196 10
3
0.001 4.660799 10
4
10
4
4.660256 10
5
10
7
4.619326 10
8
These results reect the discretization error as expected.
Note that f
(x
0
)/2 = sin(1.2)/2 0.466.
NumCSE, Lecture 1, Sept 19, 2013 24/40
Numerical Methods for Computational Science and Engineering
Numerical algorithms and errors
Results for smaller h
The above results indicate that we can compute the derivative as
accurate as we like, provided that we take h small enough.
If we wanted
cos(1.2)
sin(1.2 + h) sin(1.2)
h
< 10
10
.
We have to set h 10
10
/0.466.
The following numbers and plot are generated by
.../Greif/programs/chap01/Example1 3Figure1 3.m
NumCSE, Lecture 1, Sept 19, 2013 25/40
Numerical Methods for Computational Science and Engineering
Numerical algorithms and errors
Results for smaller h
h Absolute error
10
8
4.36105 10
10
10
9
5.594726 10
8
10
10
1.669696 10
7
10
11
7.938531 10
6
10
13
6.851746 10
4
10
15
8.173146 10
2
10
16
3.623578 10
1
These results reect both discretization and roundo errors.
NumCSE, Lecture 1, Sept 19, 2013 26/40
Numerical Methods for Computational Science and Engineering
Numerical algorithms and errors
Results for all h
The solid curve interpolates the computed values of
[f
(x
0
)
f (x
0
+h)f (x
0
)
h
[ for f (x) = sin(x) at x
0
= 1.2.
The dash-dotted straight line depicts the discretization error
without roundo error.
NumCSE, Lecture 1, Sept 19, 2013 27/40
Numerical Methods for Computational Science and Engineering
Algorithm properties
Algorithm properties
Performance features that may be expected from a good numerical
algorithm.
Accuracy
Relates to errors. How accurate is the result going to be when
a numerical algorithm is run with some particular input data.
Eciency
Robustness
(Numerical) software should run under all circumstances.
Should yield correct results to within an acceptable error or
should fail gracefully if not successful.
NumCSE, Lecture 1, Sept 19, 2013 28/40
Numerical Methods for Computational Science and Engineering
Algorithm properties
Complexity I
Complexity/computational cost of an algorithm : number of
elementary operators
Asymptotic complexity = leading order term of complexity w.r.t.
large problem size parameters
The usual choice of problem size parameters in numerical linear
algebra is the number of independent real variables needed to
describe the input data (vector length, matrix sizes).
operation description #mul/div #add/sub
inner product (x R
n
, y R
n
) x
H
y n n 1 O(n)
outer product (x R
m
, y R
n
) xy
H
nm 0 O(mn)
tensor product
matrix product (A R
mn
, B R
nk
) AB mnk mk(n 1) O(mnk)
NumCSE, Lecture 1, Sept 19, 2013 29/40
Numerical Methods for Computational Science and Engineering
Algorithm properties
Big-O and notation
For an error e depending on h we denote
e = O(h
q
)
if there are two positive constants q and C such that
[e[ C h
q
h > 0 small enough.
Similarly, for w = w(n) the expression
w = O(n log n)
means that there is a constant C > 0 such that
[w[ Cn log n as n .
NumCSE, Lecture 1, Sept 19, 2013 30/40
Numerical Methods for Computational Science and Engineering
Algorithm properties
Big-O and notation
More abstract:
Class O(f ) of functions is dened as
O(f ) = g [ c
1
, c
2
> 0 : N Z
+
: g(N) c
1
f (N) + c
2
1
0
x
n
x + 10
dx, for n = 0, 1, 2, . . . , 30.
Algorithm development: observe that analytically, for n > 0,
y
n
+ 10y
n1
=
1
0
x
n
+ 10x
n1
x + 10
dx =
1
0
x
n1
dx =
1
n
.
Also,
y
0
=
1
0
1
x + 10
dx = log(11) log(10).
Algorithm:
Evaluate y
0
= log(11) log(10).
In general, if E
n
is error after n elementary operations, cannot
avoid linear roundo error accumulation
E
n
c
0
nE
0
.