Professional Documents
Culture Documents
Numerical Analysis
西安电子科技大学
理学院数学科学系
Dept. of Mathematics
School of Science
Xidian Univ.
Chapter 1 Introduction
什么是数值分析 ?
什么是数值分析 ?
“ 数值分析”就是研究在计算机上解决数学问题的理
论和数值方法
• 数值算法的构造 : 计算公式和算法步骤
• 算法的理论分析:误差分析、收敛性、稳定性等
Chapter 1 Introduction
• 提问:数值分析是做什
么用的?
输入复杂问题或运算
数值
x, x
a , ln x , Ax b ,
b
d
分析
a
f ( x )dx ,
dx
f ( x ), ......
近似解 计算机
Chapter 1 Introduction
数值分析的学科别名
• 计算方法
• 科学与工程计算
Chapter 1 Introduction
科学计算的重要性
• 科学计算是工程实践的重要工具
• 科学计算是继理论与实验后另一科学
研 究手段
Chapter 1 Introduction
科学计算的国家战略与发展 (1)
科学计算的国家战略与发展 (2)
战略计算
•1940--1970
•Before 1940 floating point arithmetic
Newton's method Fortran
Gaussian elimination finite differences
Gauss quadrature ( 求积法 finite elements
Least-squares fitting simplex algorithm 单纯形算法
Adams and Runge-Kutta formulas Monte Carlo
Richardson extrapolation FFT
orthogonal linear algebra
•1970--1998
quasi-Newton iterations multigrid
Adaptivity Matlab
stiff ODE solvers interior point methods
software libraries spectral methods
sparse and iterative linear algebra
Chapter 1 Introduction
•1998—2048
linear algebra in O(N 2+) flops
multipole methods
breakthroughs in preconditioners, spectral methods, time stepping for PDE
* speech and graphics everywhere
* fully intelligent, adaptive numerics
* loss of determinism
* seamless interoperability
* massively parallel computing made possible by ideas related
to the human brain
* new programming methods made possible by ideas related to
natural selection
Chapter 1 Introduction
数值分析课的主要内容
• 插值和函数逼近
• 数值微分和数值积分
• 常微分方程数值解法
• 非线性方程的迭代法
• 数值代数 : 求解线性和非线性方程组的直
接
法和间接法
• 代数特征值问题的数值解法
Chapter 1 Introduction
数值分析的学科特点
构造数值算法的基本思想
近似替代
离散化
递推化
Chapter 1 Introduction
学习“计算方法”需注意如下几
点
1. 要掌握算法的原理和思想
2. 要掌握算法的处理技巧 , 步骤和计算公式
3. 重视误差分析 , 理解收敛性 , 稳定性分析的理
论
4. 做一定的理论分析证明与计算练习
5. 上机实践
§2 Introduction of error
通过测量得到模型中参数的值,观测产生误差
—— 观测误差 /* Measurement Error */
§2 Introduction of error
采用数值方法求模型的近似解,近似解与精确解之间有
误差 —— 方法误差 ( 截断误差 /* Truncation Error */ )
§2 Introduction of error
机器字长有限 , 数据在计算机中表示产生误差
—— 舍入误差 /* Roundoff Error */
§2 Introduction of error
§2 Introduction of error
1
x2
例5 : 近似计算 e dx= 0.747… …
0
x2
解法之一:将 e 作 Taylor 展开后
再积分
1
大家一起猜
1
? x4 x6 x8
2
x 2
e dx (1 x ) dx
12 ! 2 3! 4!
0 0
x
1 /1e 1
1 1e 1dx1 1 1 1
0
3 2! 5 3! 7 4! 9
1
取 0 S4 R4
2
e x dx S 4 , /* Remainder */
1 1 1 1
则 R4 由留下部分
称为截断误差 /* Truncation Error
4! 9 5! 11
/* included terms */*/
1 1
这里 R4 引起 0 .005
4! 9 由截去部分
1 1 1 /* excluded terms */
S4 1 1 0 .333 0 .1 0 .024 0 .743
3 10 42 引起
| 舍入误差 /* Roundoff Error */ 0 .0005 2 0 .001
|计算 1e -x dx 的总体误差
0
2
0 .005 0 .001 0 .006
§2 Introduction of error
NY BJ
关于本身是病态的问题,我们还是留给数学家去头痛吧!
§2 Introduction of error
1 1 n x
例 6 :计算 I n 0 x e dx , n 0 , 1 , 2 , ......
e
公式一 I n 1 n I n 1
: 1 1 x 1 记为 *
I 0 e dx 1 0 .63212056 I0
e 0 e 注意此公式精确成
则初始误差 E 0 I 0 I
0 0 .5 10 8
立
1 1 n 0 1 1 n 1 1 1
e 0
x e dx I n x e dx
e 0
e(n 1 )
In
n1
I 1* 1 1 I 0* 0 .36787944
... ... ... ... What
I10* 1 10 I 9* 0 .08812800
happened
?!
I11* 1 11 I 10* 0 .03059200
I12* 1 12 I11* 0 .63289600 ?
I13* 1 13 I12* 7 .2276480 ??
I14* 1 14 I13* 94 .959424? !
I15 1 15 I14 1423.3914 ! !
§2 Introduction of error
考察第 n 步的误差E n
| E n | | I n I n* | | (1 nI n 1 ) (1 nI n*1 ) | n |E n1| n ! | E0 |
可见初始的小扰动 | E 0 | 0 .5 10 8 迅速积累,误差呈递增走势。
造成这种情况的是不稳定的算法 /* unstable algorithm */
我们有责任改变。
1
公式二 I n 1 n I n 1 I n 1 (1 I n )
n
:方法:先估计一个 I , 再反推要求的 I ( n << N ) 。
N n
1 1
注意此公式与公式一 I N
e( N 1) N 1
在理论上等价。
1 1 1
可取 I
*
N IN
2 e( N 1) N 1
当 N 时, E N I N I N* 0
§2 Introduction of error
取 I15* 1 1 1 0 .042746233
2 e 16 16
We just got lucky?
1
I 14
*
(1 I 15*
) 0 .063816918
15
1
*
I 13 (1 I 14*
) 0 .066870220
14
1
*
I 12 (1 I 13*
) 0 .071779214
13
1
I 11 (1 I 12
* *
) 0 .077351732
12
1
*
I 10 (1 I 11* ) 0 .083877115
11
1
I 1* (1 I 2* ) 0 .36787944
2
1
I 0* (1 I 1* ) 0 .63212056
1
§2 Introduction of error
考察反推一步的误差:
1 1 1
| E N 1 | (1 I N ) (1 I N ) | E N |
*
N N N
以此类推,对 n < N 有:
1
| En | | EN |
N ( N 1) ... ( n 1)
在我们今后的讨论中,误差将不可回避,
算法的稳定性会是一个非常重要的话题。
§3 Error and Significant Digits
例 7. 用一把有毫米的刻度的米尺 , 来测量桌子的
长度 , 读出的长度 x*=1235mm
§3 Error and Significant Digits
1
例 5 中: 0 e
x2
dx 0 .743 0 .006
注: e 理论上讲是唯一确定的,可能取正,也可能取负。
不唯一,当然 越小越具有参考价值。
Of course mine is more
I can tell
accurate ! that
The distance
accuracy
between Iplanets
can tellisthat this
relates totwo
notpart’s
only the
diameter is
1 million
absolute lightbut
error, year ±1to
also
light 20cm1cm.
the size of theyear.
exact value.
§3 Error and Significant Digits
§3 Error and Significant Digits
§3 Error and Significant Digits
Def
1.
例8
例
9
§3 Error and Significant Digits
Def 2. 用科学计数法 , 记 x *
0 .a a
1 2 a n 10 m
(其中 a1 0 )。
| x x * | 0 .5 10 m n
若 an
m n
x *
(即 10
的截取按四舍五入规则),则称
例 10 有3n.1415926535
位有效数字897932 ,精确到 ; 。 * 3.1415
问: * 有几位有效数字?请证明你的结论。
证明: π* 0 .31415 101 ,
and |π * π| 0 .5 10 3 0 .5 101 4
* 有 4 位有效数字,精确到小数点后第3 位
注: 0.2300 有 4。
位有效数字,而 00023 只有 2 位有效。 12300
如果写成 0.1231055 ,则表示只有 3 位有效数字。
数字末尾的 0 不可随意省去!
§3 Error and Significant Digits
Def 1,2
例 11
例 12
§3 Error and Significant Digits
有效数字与相对误差的关系
有效数字 相对误差
限
§3 Error and Significant Digits
相对误差限 有效数
字
§3 Error and Significant Digits
例 13
例 14
§4 Error Estimation for Functions
e( y ) Mean Value e( x )
| er ( y ) | | er ( x) |
f ( x*) Theorem x
f ( x*) f ( x) x * x * x
x * x f ( x*) x *
x * f ( x*)
er ( x)
f ( x*)
相对误差条件数
/* relative condition number*
/
f 的条件数在某一点是小 \ 大,则称 f 在该点是好条件
的 /* well-conditioned */ \ 坏条件的 /* ill-conditioned */ 。
§4 Error Estimation for Functions
例 15 : 计算 y = ln x 。若 x 20 ,则取 x 的几位有效数
字可保证 y 的相对误差 < 0.1% ?
解:设截取 n 位有效数字后得 x* x ,则
x * y( x*) | e ( x) |
| er ( y ) | | er ( x) | r
y ( x*) ln x *
估计 x 和 y 的相对误差上限满足近似关系
r ( x ) ln x * r ( y )
1
10 n1 ln x * 0.1%
2a1
n4 不知道怎么办啊
x 可能是 20.# ,也可 ?
8 ln(,取最坏情
20,
.89 )
例:计算 ln 20 ,取 能是
4 位有效
19.# 即
9
8 况,即 a1 = 1 。
, 20
ln .89 ln 20
则相对误差
9 2 .0 10 5 0 .1%
8
ln 20
9
§4 Error Estimation for Functions
§4 Error Estimation for Functions
例 16
§4 Error Estimation for Functions
特例 ---- 算术运算的误差和绝对误差限分析
:
§4 Error Estimation for Functions
§4 Error Estimation for Functions
§4 Error Estimation for Functions
特例 ---- 算术运算的相对误差和相对误差限分析
:
§4 Error Estimation for Functions
§4 Error Estimation for Functions
§4 Error Estimation for Functions
§5 Remarks
§5 几点注意事项 /* Remarks *
/
1. 避免相近二数相
减
例: a = 0.12345 , a = 0.12346 ,各有 5 位有效数字
1 2
。
而 a2 a1 = 0.00001 ,只剩下 1 位有效数
几种经验性避免方法:
字。 ε ε
xε x ; ln x ε ln x ln 1 ;
xε x x
3. 避免大数吃小数
例:用单精度计算 x 2 (109 1) x 109 0
精确解为 x1 10 9的根。
, x2 1
b b 2 4ac
算法 1 :利用求根公式 x
2a
在计算机内, 109 存为 0.11010 , 1 存为 0.1101 。做加法时
,两加数的指数先向大指数对齐,再将浮点部分相加。即 1
的指数部分须变为 1010 ,则: 1 = 0.0000000001 1010 ,取单
精度时就成为:
109+1=0.100000001010+0.00000000 1010=0.10000000 1010
b b 2 4大数吃小数
ac b b 2 4ac
x1 10 , x 2
9
0
2a 2a
§5 Remarks
b sign(b ) b 4ac
2
算法 2 :先解出 x1 109
2a
c c 109
再利用 x1 x2 x2 9 1
a a x1 10
注:求和时从小到大相加,可使和的误差减小。
例:按从小到大、以及从大到小的顺序分别计算
1 + 2 + 3 + … + 40 + 109
4. 先化简再计算,减少步骤,避免误差积累。
一般来说,计算机处理下列运算的速度为 , , exp
5. 选用稳定的算法
。
评价算法的准则:复杂度、精度、稳定性