You are on page 1of 58

数值分析

Numerical Analysis

西安电子科技大学
理学院数学科学系
Dept. of Mathematics
School of Science
Xidian Univ.
Chapter 1 Introduction

什么是数值分析 ?

Numerical Analysis is concerned with


the design and analysis of algorithms for solving
mathematical problems that arise in many fields,
especially science and engineering.
----Michael T. Heath
Numerical analysis is the study of
algorithms for the problems of continuous
mathematics.
----Lloyd N. Trefethen
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)

• 1983 年一个由美国著名数学家拉克斯 (P. Lax) 为首的不同学


科的专家委员会向美国政府提出的报告之中,强调“科学计算是关
系到国家安全、经济发展和科技进步的关键性环节,是事关国家
命脉的大事。”
• 1984 年美国政府大幅度地增加对科学计算经费的支持 , 新建

五个国家级超级计算中心(分别在普林斯顿大学、圣地亚哥、伊
里诺大学、康奈尔大学、匹兹堡大学),配备当时最高性能的计算
机,建立 NSF -net 新网络。
• 80 年代中期我国将“大规模科学与工程计算”列入国家资助重
大项目。
Chapter 1 Introduction

科学计算的国家战略与发展 (2)

• 1987 年起美国 NSF 把“科学与工程计算” ,“生物工程”


“全局性科学”作为三大优先资助的领域。
• 1990 年美国国家研究委员会发表《振兴美国数学: 90 年代
的计划》的报告,建议对由计算引发的数学给予特殊的鼓励和资
助。
• 1991 年以美国总统倡议的形式提出了“高性能计算与通信 HP
CC
计划”, 这是为了保持和提高美国在计算和网络的所有先进领域
中的领导地位而制定的。其发展的关键技术是可扩展的大规模并
行计算。
• 1995 年美国为了确保核库存的性能安全性、可靠性和更新需
要而实施的“加速战略计算创新 ASCI 计划”。
Chapter 1 Introduction

战略计算

• 这是因为美国克林顿总统在 1995 年 8 月 11 日宣布:


“美国决定谋求真正的“零当量”全面禁止试验核武器条约”。
• 这并不意味着核竞赛的结束,恰恰相反是核武器计划新时代
的开始,要求通过逼真的建模和模拟计算来取代传统的反复
试验的工程处理方法,这主要依赖于先进的数值计算和模拟
能力。
• 1995 年 8 月 22 日(即美国总统宣布决定后的 11 天),能
源部 DOE 就采购世界上最快的一台计算机(速度超过万亿次
运算)交付圣地亚哥实验室( 96 年 12 月安装)。
• 1998 年 7 月 30-31 日,美国 DOE/FNS 共同联合组织召
开了关于“先进科学计算”的全国会议,会议强调科学模拟的
重要性,希望应用科学模拟来攻克复杂的科学与工程难题。
Chapter 1 Introduction

Some past developments in scientific computing


----Lloyd N. Trefethen

•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

The future development in scientific computing


----Lloyd N. Trefethen

•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

数值分析的学科特点

实用性 理论性 实践性


1 面向计算机,根据计算机的特点提供可行的有效算法;
• 只提供加减乘除和逻辑运算
• 串行机和并行机
2 有可靠的理论分析 : 算法的收敛性、稳定性和误差分析;
3 有好的计算复杂性 : 时间和空间复杂性;
4 有充分的数值实验证明算法的有效性。
Chapter 1 Introduction

构造数值算法的基本思想

近似替代
离散化
递推化
Chapter 1 Introduction

学习“计算方法”需注意如下几

1. 要掌握算法的原理和思想
2. 要掌握算法的处理技巧 , 步骤和计算公式
3. 重视误差分析 , 理解收敛性 , 稳定性分析的理

4. 做一定的理论分析证明与计算练习
5. 上机实践
§2 Introduction of error

§2 误差的基本理论 /* Introduction of error*


/
§2 Introduction of error
§2 Introduction of error

1. 误差的来源与分类 /* Source & Classification


*/
 从实际问题中抽象 ( 简化 ) 出数学模型 , 模型与实际问
题之间存在误差 —— 模型误差 /* Modeling
Error */
§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

2. 传播与积累 /* Spread & Accumulation */


例:蝴蝶效应 —— 纽约的一只蝴蝶翅膀一拍,风和日丽的北京就
刮起台风来了?!

NY BJ

以上是一个病态问题 /* ill-posed problem*/

关于本身是病态的问题,我们还是留给数学家去头痛吧!
§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 
n1
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 n1|    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)

误差逐步递减 , 这样的算法称为稳定的算法 /* stable algorith


m */

在我们今后的讨论中,误差将不可回避,

算法的稳定性会是一个非常重要的话题。
§3 Error and Significant Digits

§3 误差与有效数字 /* Error and Significant Digits *


/
§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 20cm1cm.
the size of theyear.
exact value.
§3 Error and Significant Digits
§3 Error and Significant Digits
§3 Error and Significant Digits

 有效数字 /* 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.1231055 ,则表示只有 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

§4 函数的误差估计 /*Error Estimation for Functions


*/
问题:对于 y = f (x) ,若用 x* 取代 x ,将对 y 产生什么影响?

分析: e (y) = f (x*)  f (x) Mean Value e (x) = x*  x


Theorem
= f ( )(x* 
x)
x* 与 x 非常接近时,可认为 f ( )  f (x*) ,则有

|e (y)|  | f (x*)|·|e(x)|
即: x* 产生的误差经过 f 作用后被放大 / 缩小了 | f 
(x*)| 倍。故称 | f (x*)| 为放大因子 /* amplification fact
or */ 或 绝对条件数 /* absolute condition number */.
§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  n1  ln x *  0.1%
2a1
 n4 不知道怎么办啊
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

当 | x | << 1 时 1  cos x  2 sin 2 x ;


: 2
 1 1 
e x  1  x  1  x  x 2  ... 
 2 6 
§5 Remarks
§5 Remarks

3. 避免大数吃小数
例:用单精度计算 x 2  (109  1) x  109  0
精确解为 x1  10 9的根。
, x2  1
 b  b 2  4ac
 算法 1 :利用求根公式 x
2a
在计算机内, 109 存为 0.11010 , 1 存为 0.1101 。做加法时
,两加数的指数先向大指数对齐,再将浮点部分相加。即 1
的指数部分须变为 1010 ,则: 1 = 0.0000000001  1010 ,取单
精度时就成为:
109+1=0.100000001010+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. 选用稳定的算法

评价算法的准则:复杂度、精度、稳定性

You might also like