finite precision computation ( ). num=0; eps=1; while (1+eps)>1 eps=eps/2; num=num+1; end...
Post on 04-Apr-2015
111 Views
Preview:
TRANSCRIPT
Finite Precision Computation ( 续 )
武汉大学数学与统计学院向华
num=0EPS=1while (1+EPS)gt1EPS=EPS2num=num+1end
x=zeros(110)for n=110x(n)=sin(npi10)end
EPS=1 for num=11000EPS=EPS2if (1+EPS)lt=1EPS=EPS2BreakEndend
控制语句控制语句
for variable=expression Statementsend
while expression Statementsend
If expression Statementsend
switch x case 1 statement1 case statement2 otherwiseend
关系运算符关系运算符==
~=
amp
|
~
XOR
Matlab 编程
注释
续行 hellip
例
x=zeros(110)for n=110 x(n)=sin(npi10)end
num=0EPS=1while (1+EPS)gt1 EPS=EPS2 num=num+1end
EPS=1 for num=11000 EPS=EPS2 if (1+EPS)lt=1 EPS=EPS2 break endend
g=2for k=1100 g=1+1gendg
111
1
11
11
11
11
11
11
11
)(3
8)()()(
)()()()(28)(
)()(10)(
3213
31212
121
tytytytydt
d
tytytytytydt
d
tytytydt
d
function yprime = lorenzeq(ty)yprime = [ 10( y(2)-y(1) ) 28y(1) -y(2) -y(1)y(3) y(1)y(2) -83 y(3) ]
ODE solvert = [0 50]y0= [010][ty] = ode45(lorenzeqty0)plot( y(1)y(3) )xlabel(y_1)ylabel(y_2)title( Lorenz equationsFontSize16)
2^(1-53)ans = 2220446049250313e-016xmin=2^(-1021-1)xmin = 2225073858507201e-308xmin=2^(-1021-1-52)xmin = 4940656458412465e-324
eps=2220446049250313e-016realmax=1797693134862316e+308realmin=2225073858507201e-308 11realmax=Inf
00=NaN infinf=NaN
realmineps=4940656458412465e-324
realmineps01=0
MATLAB
double precision (64-bit word)
16 significant decimal digits
F(253-10211024true)
In[4]= N1 25321024 20Out[4]= 17976931348623157081 10308
)( maxmin denormeepbF
1min
min ebxpebx min
min
max)1(maxep bbx
a=1b=1while a+b~=a b=b2end
a=10e+308b=11e+308c=-1001e+308a+(b+c)a+b+c
numerical cancellationx=1e-15((1+x)-1)x
Chaque calcul simple est ensuite fait au mieux le processeur renvoie lemeilleur resultat possible (norme IEEE-754) etant donnes ses imperatifs3142 = 9859 6 rarr 986Chaque resultat de calcul est donc arrondi
M^eme si un calcul est presque juste une succession de calculs est parfois fausse π2 rarr 3142 = 9859 6 rarr 986Mais π 2 = 9869 604 hellip donc le nombre ottant le plus proche est 987
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in factor form
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in series form
7899 14418)2()( xxxxxp
舍入误差的影响舍入误差的影响
82982839)( 23 xxxxP
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
num=0EPS=1while (1+EPS)gt1EPS=EPS2num=num+1end
x=zeros(110)for n=110x(n)=sin(npi10)end
EPS=1 for num=11000EPS=EPS2if (1+EPS)lt=1EPS=EPS2BreakEndend
控制语句控制语句
for variable=expression Statementsend
while expression Statementsend
If expression Statementsend
switch x case 1 statement1 case statement2 otherwiseend
关系运算符关系运算符==
~=
amp
|
~
XOR
Matlab 编程
注释
续行 hellip
例
x=zeros(110)for n=110 x(n)=sin(npi10)end
num=0EPS=1while (1+EPS)gt1 EPS=EPS2 num=num+1end
EPS=1 for num=11000 EPS=EPS2 if (1+EPS)lt=1 EPS=EPS2 break endend
g=2for k=1100 g=1+1gendg
111
1
11
11
11
11
11
11
11
)(3
8)()()(
)()()()(28)(
)()(10)(
3213
31212
121
tytytytydt
d
tytytytytydt
d
tytytydt
d
function yprime = lorenzeq(ty)yprime = [ 10( y(2)-y(1) ) 28y(1) -y(2) -y(1)y(3) y(1)y(2) -83 y(3) ]
ODE solvert = [0 50]y0= [010][ty] = ode45(lorenzeqty0)plot( y(1)y(3) )xlabel(y_1)ylabel(y_2)title( Lorenz equationsFontSize16)
2^(1-53)ans = 2220446049250313e-016xmin=2^(-1021-1)xmin = 2225073858507201e-308xmin=2^(-1021-1-52)xmin = 4940656458412465e-324
eps=2220446049250313e-016realmax=1797693134862316e+308realmin=2225073858507201e-308 11realmax=Inf
00=NaN infinf=NaN
realmineps=4940656458412465e-324
realmineps01=0
MATLAB
double precision (64-bit word)
16 significant decimal digits
F(253-10211024true)
In[4]= N1 25321024 20Out[4]= 17976931348623157081 10308
)( maxmin denormeepbF
1min
min ebxpebx min
min
max)1(maxep bbx
a=1b=1while a+b~=a b=b2end
a=10e+308b=11e+308c=-1001e+308a+(b+c)a+b+c
numerical cancellationx=1e-15((1+x)-1)x
Chaque calcul simple est ensuite fait au mieux le processeur renvoie lemeilleur resultat possible (norme IEEE-754) etant donnes ses imperatifs3142 = 9859 6 rarr 986Chaque resultat de calcul est donc arrondi
M^eme si un calcul est presque juste une succession de calculs est parfois fausse π2 rarr 3142 = 9859 6 rarr 986Mais π 2 = 9869 604 hellip donc le nombre ottant le plus proche est 987
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in factor form
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in series form
7899 14418)2()( xxxxxp
舍入误差的影响舍入误差的影响
82982839)( 23 xxxxP
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
控制语句控制语句
for variable=expression Statementsend
while expression Statementsend
If expression Statementsend
switch x case 1 statement1 case statement2 otherwiseend
关系运算符关系运算符==
~=
amp
|
~
XOR
Matlab 编程
注释
续行 hellip
例
x=zeros(110)for n=110 x(n)=sin(npi10)end
num=0EPS=1while (1+EPS)gt1 EPS=EPS2 num=num+1end
EPS=1 for num=11000 EPS=EPS2 if (1+EPS)lt=1 EPS=EPS2 break endend
g=2for k=1100 g=1+1gendg
111
1
11
11
11
11
11
11
11
)(3
8)()()(
)()()()(28)(
)()(10)(
3213
31212
121
tytytytydt
d
tytytytytydt
d
tytytydt
d
function yprime = lorenzeq(ty)yprime = [ 10( y(2)-y(1) ) 28y(1) -y(2) -y(1)y(3) y(1)y(2) -83 y(3) ]
ODE solvert = [0 50]y0= [010][ty] = ode45(lorenzeqty0)plot( y(1)y(3) )xlabel(y_1)ylabel(y_2)title( Lorenz equationsFontSize16)
2^(1-53)ans = 2220446049250313e-016xmin=2^(-1021-1)xmin = 2225073858507201e-308xmin=2^(-1021-1-52)xmin = 4940656458412465e-324
eps=2220446049250313e-016realmax=1797693134862316e+308realmin=2225073858507201e-308 11realmax=Inf
00=NaN infinf=NaN
realmineps=4940656458412465e-324
realmineps01=0
MATLAB
double precision (64-bit word)
16 significant decimal digits
F(253-10211024true)
In[4]= N1 25321024 20Out[4]= 17976931348623157081 10308
)( maxmin denormeepbF
1min
min ebxpebx min
min
max)1(maxep bbx
a=1b=1while a+b~=a b=b2end
a=10e+308b=11e+308c=-1001e+308a+(b+c)a+b+c
numerical cancellationx=1e-15((1+x)-1)x
Chaque calcul simple est ensuite fait au mieux le processeur renvoie lemeilleur resultat possible (norme IEEE-754) etant donnes ses imperatifs3142 = 9859 6 rarr 986Chaque resultat de calcul est donc arrondi
M^eme si un calcul est presque juste une succession de calculs est parfois fausse π2 rarr 3142 = 9859 6 rarr 986Mais π 2 = 9869 604 hellip donc le nombre ottant le plus proche est 987
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in factor form
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in series form
7899 14418)2()( xxxxxp
舍入误差的影响舍入误差的影响
82982839)( 23 xxxxP
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
g=2for k=1100 g=1+1gendg
111
1
11
11
11
11
11
11
11
)(3
8)()()(
)()()()(28)(
)()(10)(
3213
31212
121
tytytytydt
d
tytytytytydt
d
tytytydt
d
function yprime = lorenzeq(ty)yprime = [ 10( y(2)-y(1) ) 28y(1) -y(2) -y(1)y(3) y(1)y(2) -83 y(3) ]
ODE solvert = [0 50]y0= [010][ty] = ode45(lorenzeqty0)plot( y(1)y(3) )xlabel(y_1)ylabel(y_2)title( Lorenz equationsFontSize16)
2^(1-53)ans = 2220446049250313e-016xmin=2^(-1021-1)xmin = 2225073858507201e-308xmin=2^(-1021-1-52)xmin = 4940656458412465e-324
eps=2220446049250313e-016realmax=1797693134862316e+308realmin=2225073858507201e-308 11realmax=Inf
00=NaN infinf=NaN
realmineps=4940656458412465e-324
realmineps01=0
MATLAB
double precision (64-bit word)
16 significant decimal digits
F(253-10211024true)
In[4]= N1 25321024 20Out[4]= 17976931348623157081 10308
)( maxmin denormeepbF
1min
min ebxpebx min
min
max)1(maxep bbx
a=1b=1while a+b~=a b=b2end
a=10e+308b=11e+308c=-1001e+308a+(b+c)a+b+c
numerical cancellationx=1e-15((1+x)-1)x
Chaque calcul simple est ensuite fait au mieux le processeur renvoie lemeilleur resultat possible (norme IEEE-754) etant donnes ses imperatifs3142 = 9859 6 rarr 986Chaque resultat de calcul est donc arrondi
M^eme si un calcul est presque juste une succession de calculs est parfois fausse π2 rarr 3142 = 9859 6 rarr 986Mais π 2 = 9869 604 hellip donc le nombre ottant le plus proche est 987
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in factor form
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in series form
7899 14418)2()( xxxxxp
舍入误差的影响舍入误差的影响
82982839)( 23 xxxxP
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
2^(1-53)ans = 2220446049250313e-016xmin=2^(-1021-1)xmin = 2225073858507201e-308xmin=2^(-1021-1-52)xmin = 4940656458412465e-324
eps=2220446049250313e-016realmax=1797693134862316e+308realmin=2225073858507201e-308 11realmax=Inf
00=NaN infinf=NaN
realmineps=4940656458412465e-324
realmineps01=0
MATLAB
double precision (64-bit word)
16 significant decimal digits
F(253-10211024true)
In[4]= N1 25321024 20Out[4]= 17976931348623157081 10308
)( maxmin denormeepbF
1min
min ebxpebx min
min
max)1(maxep bbx
a=1b=1while a+b~=a b=b2end
a=10e+308b=11e+308c=-1001e+308a+(b+c)a+b+c
numerical cancellationx=1e-15((1+x)-1)x
Chaque calcul simple est ensuite fait au mieux le processeur renvoie lemeilleur resultat possible (norme IEEE-754) etant donnes ses imperatifs3142 = 9859 6 rarr 986Chaque resultat de calcul est donc arrondi
M^eme si un calcul est presque juste une succession de calculs est parfois fausse π2 rarr 3142 = 9859 6 rarr 986Mais π 2 = 9869 604 hellip donc le nombre ottant le plus proche est 987
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in factor form
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in series form
7899 14418)2()( xxxxxp
舍入误差的影响舍入误差的影响
82982839)( 23 xxxxP
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
a=1b=1while a+b~=a b=b2end
a=10e+308b=11e+308c=-1001e+308a+(b+c)a+b+c
numerical cancellationx=1e-15((1+x)-1)x
Chaque calcul simple est ensuite fait au mieux le processeur renvoie lemeilleur resultat possible (norme IEEE-754) etant donnes ses imperatifs3142 = 9859 6 rarr 986Chaque resultat de calcul est donc arrondi
M^eme si un calcul est presque juste une succession de calculs est parfois fausse π2 rarr 3142 = 9859 6 rarr 986Mais π 2 = 9869 604 hellip donc le nombre ottant le plus proche est 987
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in factor form
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in series form
7899 14418)2()( xxxxxp
舍入误差的影响舍入误差的影响
82982839)( 23 xxxxP
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
Chaque calcul simple est ensuite fait au mieux le processeur renvoie lemeilleur resultat possible (norme IEEE-754) etant donnes ses imperatifs3142 = 9859 6 rarr 986Chaque resultat de calcul est donc arrondi
M^eme si un calcul est presque juste une succession de calculs est parfois fausse π2 rarr 3142 = 9859 6 rarr 986Mais π 2 = 9869 604 hellip donc le nombre ottant le plus proche est 987
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in factor form
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in series form
7899 14418)2()( xxxxxp
舍入误差的影响舍入误差的影响
82982839)( 23 xxxxP
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in factor form
19 192 194 196 198 2 202 204 206 208 21-15
-1
-05
0
05
1
15x 10
-10 Polynomial evaluated in series form
7899 14418)2()( xxxxxp
舍入误差的影响舍入误差的影响
82982839)( 23 xxxxP
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
82982839)( 23 xxxxP
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
82982839)( 23 xxxxP
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
Orientation de 3 points (G Melquiond)Etant donnes 3 points du plan p q et r On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire
float det = ( qx - px ) ( r y - py )1048576 - ( qy - py ) ( r x - px ) i f ( det gt 0) return POSITIVE i f ( det lt 0) return NEGATIVE return ZERO
p
r
q
pyrypyqy
pxrxpxqxsignerqporient
)(2
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
Premiere guerre du Golfe - 100h plus tard28 GI morts et 98 blesses
iraquiens US
antiminusmissile Patriotmissile Scud
Premiere guerre du Golfe - explicationLanti-missile Patriot est prevu pour fonctionner pendant quelques heuresMais ca marchait tellement bien quils lont laisse brancheLhorloge interne ajoute 01s a chaque tic Mais 01 nest pas exact en binaire rarr une petite erreur a chaque ticrarr au bout de 100h une erreur susante pour rater le missile
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
Mon banquier ma propose cet investissement vous me donnez e=271828 currenlannee suivante je prends 1curren de frais et je multiplie par 1lannee suivante je prends 1curren de frais et je multiplie par 2lannee suivante je prends 1curren de frais et je multiplie par 3 apres n ans je prends 1curren de frais et je multiplie par nPour recuperer mon argent il y a 1curren de fraisDans 50 ans pour ma retraite combien dargent aurai-je
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
6500127190887506580397803840893860464266619976132998982702001269694679091261802058160555785871702272129904252549070848000000000
Matlab 或 C(format double)
x = 27182818284590452354for annee = 1 50 x = (x - 1) anneeend x = -4396803930182069e+048
00200
x
Fori 1 i 51 i x x 1ix SimplifyxNx 1 10
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
MATLAB1718281828459045e+0001436563656918090e+0001309690970754271e+0001238763883017082e+0001193819415085411e+0001162916490512465e+0001140415433587258e+0001123323468698061e+0001109911218282548e+0001099112182825479e+0001090234011080270e+0001082808132963237e+0001076505728522079e+0001071080199309108e+0001066202989636622e+0001059247834185953e+0001007213181161205e+0001298372609016951e-001-1653309204286779e+001-3506618408573559e+002-7384898658004473e+003
1718281828459045
1436563656918090
1309690970754271
1238763883017086
1193819415085428
1162916490512569
1140415433587986
1123323468703890
1109911218335008
1099112183350075
1090234016850830
1082808202209954
1076506628729406
1071092802211678
1066392033175171
1062272530802742
1058633023646621
1055394425639172
1052494087144259
1049881742885176
1047516600588701
Mathematica
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
includeltmathhgtmain()int n=1double x=10 h=10 deriv=cos(x) diffquoerror f(x)=sin(x) printf(deriv=136enderiv)printf(h diffquo abs(deriv-diffquo) n)
while(nlt=20)h=h10diffquo=(sin(x+h)-sin(x))herror=fabs(deriv-diffquo)printf(51e 136e 136e n h diffquo error)n++
h
xfhxfxf
)()()(
Approximating a derivative by a difference quotient
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
The truncation error of the finite difference approximation is bounded by Mh2 Assuming the error in function values is bounded by ε the rounding error is bounded by 2 εh Total computational error is
h
Mh 22
8102 Mh
Where M is a bound on |frdquo(t)| for t near x There is a tradeoff between truncation error and rounding error in choosing the step size h It is minimized when
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
x=ones(351)x(1)=112x(2)=6111for i=335 x(i)=111-(1130-3000x(i-2))x(i-1)endx(35)
Consider the recurrence
In exact arithmetic the xk form a monotonically increasing sequence that converges to 6 Implement the recurrence and compare the computed x34 with the true value 5998 (to four correct signicant figures)
1161211
)30001130(111
10
11
xx
xxx kkk
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
1161211
)30001130(111
10
11
xx
xxx kkk
30001130111)( 23 xxxxp
)100()55(3025251130111)( 223 xxxxxxq
The mathematical convergence depends on the initial conditions x0 x1convergence to 100 for almost all (x0 x1)convergence to 6 x0(11- x1)=30convergence to 5 x0=x1=5 (exactly in machine representation)
fplot(x^3-111x^2+1130x-3000[-400400])
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
fplot(x^3-111x^2+1130x-3000[47]) fplot(x^3-111x^2+1130x-3000[-10110])
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
syms x1 x2 x3x1=sym(11)sym(2)x2=sym(6111)for i=335 x3=111-(1130-3000x1)x2 x1=x2 x2=x3endx3x3=1721981182794095961389986301287093876567205105910375321asymp599797252168491
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
Array[x35]x[1]=112x[2]=6111Do[x[i+2]=111-(1130-3000x[i])x[i+1]i133](For[i=1ilt=33i++x[i+2]=111-(1130-3000x[i])x[i+1]])(While[ilt=33x[i+2]=111-(1130-3000x[i])x[i+1]i++] )x[35]
037532167205105912870938765
8998630179409596131721981182
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
Cancellationgtgtx=12e-8 (1-cos(x))x^2ans=07710
保留 32位有效数字得049999999999999999400001004443762gtgt
2
2
)2sin(
2
1
x
x
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
acb 42
acxx
a
acbbsignbx
2
4)(
21
2
1
))()(( csbsassA
))())(())(((4
1cbabaccbaA
Solving a Quadratic EquationIf
Rename a b c so that agebgec (Kahan)
The parentheses are essential
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
n
iin xx
ns
1
22
1
1
n
iixn
x1
1
2
11
22 1
1
1 n
ii
n
iin xn
xn
s
Computing the Sample Variance
(requires two passes through the data)
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
)1exp(e
n
n ne
11lim
Accumulation of Rounding ErrorsApproximate
by taking finite n in the definition
e=exp(1)for i=115 n=10^i (1+1n)^n-eend
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
11 10
1
1
01
11
1
A
11)1( fl
10
00
0
1
1
01
11
1ˆˆ11
ULA
Instability Without Cancellation(1) The Need for Pivoting
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
(2) An Innocuous Calculation
for i=160 x=sqrt(x)endfor i=160 x=x^2end
gtgtx=10ans=1
gtgtx=05ans=0
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
(3) An Infinite Sum
48644934066816
1 2
12
n n
Sum in the opposite order from smallest to largest
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
||||
xxx
Axx
504010
407030
206040
A
Rounding Errors Can Be BeneficialPower method
Consider the matrix
Which has eigenvalues 0 04394 1161 and an eigenvector [111]T
corresponding to the eigenvalue zero
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
Gauss
Givens
Neumann
Goldstine
Turing
Wilkinson
Backward error analysis
Condition number
)( Afx A
AA
)(~ AAfx
le 向前误差 条件数 X 向后误差
数据 解
(A nearby problem)
Condition number backward error
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
数值运算的简单原则 运算次序 求和时从小到大相加避免相近的数相减避免小分母 分母小会造成浮点溢出避免大数吃小数简化计算步骤选用稳定的算法
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
References1 C W Ueberhuber Numerical Computation 1 Springer 19972 Sylvie Boldo Pourquoi mon ordinateur calcule faux CR INRIA-Equip
e-projet ProVal 18 janvier 20083 M T Heath Scientific Computing An Introductory Survey McGraw-Hil
l Companies Inc 20024 M L Overton Numerical Computing with IEEE Floating Point Arithmet
ic SIAM 20015 N Higham Accuracy ans Stability of Numerical Algorithms 2nd edition
SIAM 2002
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
1 用 For 循环计算
2 用 While 循环找到最小的正整数 k 使得
3 计算函数值
4 取 n=10^15 计算
5 下一题复习用 Matlab 做图并为下次内容做准备做出下面二次型对应的曲面
提示[X Y]=meshgrid(-6056)Z=05(3X^2 + 4XY+6Y^2)-2X+8Y再用 surf(XYZ)
100000
12
1
n n
)1021()cos(1
)( 82
fx
xxf
n
nnf
11)(
8
2
62
23
2
1)(
bAxbAxxxf TT
124
14
10590
1
k
n n
- Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
-
top related