ee 3561_unit_1(c)al-dhaifallah 14351 number representation normalized floating point...
TRANSCRIPT
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 1
Number Representation Normalized Floating Point Representation Significant Digits Accuracy and Precision Rounding and Chopping
Reading assignment: Chapter 2
Lecture 2 Number Representation and
accuracy
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 2
Representing Real Numbers You are familiar with the decimal system
Decimal System Base =10 , Digits(0,1,…9) Standard Representations
21012 10510410210110345.312
part part
fraction integralsign
54.213
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 3
Normalized Floating Point Representation Normalized Floating Point Representation
No integral part, Advantage Efficient in representing very small or very large numbers
integer:,0
exponent mantissa sign
10.0
1
4321
nd
dddd n
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 4
Binary System
Binary System Base=2, Digits{0,1}
exponent mantissasign
21.0 432nbbb
10 11 bb
1010321
2 )625.0()212021()101.0(
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 5
7-Bit Representation(sign: 1 bit, Mantissa 3bits,exponent 3 bits)
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 6
Fact Number that have finite expansion in one numbering
system may have an infinite expansion in another numbering system
You can never represent 0.1 exactly in any computer
210 ...)011000001100110.0()1.0(
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 7
Representation Hypothetical Machine (real computers use ≥ 23 bit
mantissa)
Example:
If a machine has 5 bits representation distributed as follows
Mantissa 2 bits exponent 2 bit sign 1 bit
Possible machine numbers
(0.25=00001) (0.375= 01111) (1.5=00111)
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 8
Representation
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Gap near zero
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 9
Remarks
Numbers that can be exactly represented are called machine numbers
Difference between machine numbers is not uniform. So, sum of machine numbers is not necessarily a machine number
0.25 + .375 =0.625 (not a machine number)
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 10
Significant Digits Significant digits are those digits that can be
used with confidence.
0 1 2 3 4
Length of green rectangle = 3.45significant
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 11
Loss of Significance Mathematical operations may lead to
reducing the number of significant digits
0.123466 E+02 6 significant digits
─ 0.123445 E+02 6 significant digits
──────────────
0.000021E+02 2 significant digits
0. 210000E-02Subtracting nearly equal numbers causes loss of significance
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 12
Accuracy and Precision Accuracy is related to closeness to the true value
Precision is related to the closeness to other estimated
values
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 13
Better Precision
Better accuracy
Accuracy is related to closeness to the true value Precision is related to the closeness to other estimated values
Accuracy and Precision
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 14
Rounding and Chopping Rounding: Replace the number by the nearest machine number Chopping: Throw all extra digits
0 1 2
True 1.1681
Rounding (1.2) Chopping (1.1)
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 15
Error DefinitionsTrue Error
can be computed if the true value is known
100* valuetrue
ionapproximat valuetrue
Errorelative Percent RAbsolute
ionapproximat valuetrue
ErrorTrue Absolute
t
tE
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 16
Error DefinitionsEstimated error
Used when the true value is not known
100*estimatecurrent
estimate prevoius estimatecurrent
Errorelative Percent RAbsolute Estimated
estimate prevoius estimatecurrent
ErrorAbsolute Estimated
a
aE
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 17
Notation
We say the estimate is correct to n decimal digits if
We say the estimate is correct to n decimal digits rounded if
n10Error
n 102
1Error
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 18
Summary Number Representation
Number that have finite expansion in one numbering system may
have an infinite expansion in another numbering system.
Normalized Floating Point Representation Efficient in representing very small or very large numbers Difference between machine numbers is not uniform Representation error depends on the number of bits used in the
mantissa.
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 19
Summary Rounding Chopping Error Definitions:
Absolute true error True Percent relative error Estimated absolute error Estimated percent relative error
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 20
Lecture 3Taylor Theorem
Motivation Taylor Theorem Examples
Reading assignment: Chapter 4
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 21
Motivation
We can easily compute expressions like
?)6.0sin(,4.1 computeyou do HowBut,
)4(2
103 2
x
way?practical a thisis
?)6.0sin(
compute todefinition theusecan We
0.6
ab
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 22
Taylor Series
∑∞
000
)(
000
)(
30
0)3(
20
0)2(
00'
0
0
)()(!
1)(
can write weconverge series theif
)()(!
1
...)(!3
)()(
!2
)()()()(
about )( ofexpansion seriesTaylor The
k
kk
k
kk
xxxfk
xf
xxxfk
SeriesTaylor
or
xxxf
xxxf
xxxfxf
xxf
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 23
Taylor SeriesExample 1
∞xfor converges series The
!)()(
!
1
11)0()(
1)0()(
1)0(')('
1)0()(
∑∑∞
0
∞
000
)(
)()(
)2()2(
k
k
k
kkx
kxk
x
x
x
k
xxxxf
ke
kforfexf
fexf
fexf
fexf
0about )( ofexpansion seriesTaylor Obtain 0 xexf x
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 24
Taylor SeriesExample 1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 10
0.5
1
1.5
2
2.5
3
1
1+x
1+x+0.5x2
exp(x)
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 25
Taylor SeriesExample 2
∞xfor converges series The
....!7!5!3
)(!
)()sin(
1)0()cos()(
0)0()sin()(
1)0(')cos()('
0)0()sin()(
753∞
00
0)(
)3()3(
)2()2(
∑
xxxxxx
k
xfx
fxxf
fxxf
fxxf
fxxf
k
kk
0about )sin()( ofexpansion seriesTaylor Obtain 0 xxxf
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 26
-4 -3 -2 -1 0 1 2 3 4-4
-3
-2
-1
0
1
2
3
4
x
x-x3/3!
x-x3/3!+x5/5!
sin(x)
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 27
Convergence of Taylor Series(Observations, Example 1)
The Taylor series converges fast (few terms are needed) when x is near the point of expansion. If |x-c| is large then more terms are needed to get good approximation.
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 28
Taylor SeriesExample 3
....11
1 ofExpansionSeriesTaylor
6)0(1
6)(
2)0(1
2)(
1)0(1
1)('
1)0(1
1)(
01
1f(x) ofexpansion seriesTaylor Obtain
32
4)3(
3)2(
2
0
xxxx
fx
xf
fx
xf
fx
xf
fx
xf
xaboutx
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 29
Example 3remarks
Can we apply Taylor series for x>1??
How many terms are needed to get good approximation???
These questions will be answered using Taylor Theorem
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 30
Taylor Theorem
. andbetween x is)()!1(
)(
where
)(!
)()(
bygiven is at value then the, and
containing intervalan on continuous
are sderavative 1first its andfunction a If
1)1(
1
1
n
0
)(
∑
candcxn
fE
Ecxk
cfxf
xxc
nf(x)
nn
n
nk
kk
(n+1) terms Truncated Taylor Series
Reminder
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 31
Taylor Theorem
.applicablenot is TheoremTaylor
defined.not are sderivative
its andfunction then the1],0[
1||if0expansion ofpoint with 1
1
for oremTaylor theapply can We
includesxif
xcx
f(x)
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 32
Error Term
. and between allfor
)()!1(
)(
on boundupper an derivecan We
errorion approximat about the ideaan get To
1)1(
1
xcofvalues
cxn
fE n
n
n
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 33
Example 4 (The Approximation Error)
0514268.82.0)!1(
)()!1(
)(
1≥≤)()(
41
2.0
1
1)1(
1
2.0)()(
EEn
eE
cxn
fE
kforefexf
nn
nn
n
kxk
?2.00about
expansion seriesTaylor its of3)(n terms4first the
by )( replaced weiferror theis large How
xwhenc
exf x
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 34
Example 5
? 1with xe eapproximat to
used are terms1)(n when beerror can the largeHow
expansion) ofcenter (the5.0ef(x) of
expansion seriesTaylor theObtain
12x
12x
cabout
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 35
Example 5
...!
)5.0(2...
!2
)5.0(4)5.0(2
)5.0(!
)5.0(
2)5.0(2)(
4)5.0(4)(
2)5.0('2)('
)5.0()(
22
222
∞
0
)(12
2)(12)(
2)2(12)2(
212
212
∑
k
xe
xexee
xk
fe
efexf
efexf
efexf
efexf
kk
k
kk
x
kkxkk
x
x
x
5.0,)( ofexpansion seriesTaylor Obtain 12 cexf x
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 36
Example 5Error term
)!1(
max)!1(
)5.01(2
1when
)!1(
)5.0(2
)5.0()!1(
)(
2)(
3
12
]1,5.0[
11
1121
1)1(
12)(
n
eError
en
Error
x
n
xeError
xn
fError
exf
nn
nn
nn
xkk
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 37
Alternative form of Taylor Theorem
hxxwherehn
fE
Ehk
xfhxf
[a,b]hx[a,b]x
[a,b]
xfLet
nn
n
n
n
k
kk
and between is)!1(
)(
!
)()(
then and and
, intervalan on 1)1,2,...(n orders
of sderivative continuous have)(
1)1(
1
10
)(
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 38
Taylor TheoremAlternative forms
hxxwhere
hn
fh
k
xfhxf
xchxx
cxwhere
cxn
fcx
k
cfxf
nnn
k
kk
nnn
k
kk
and between is
)!1(
)(
!
)()(
,
and between is
)()!1(
)()(
!
)()(
1)1(
0
)(
1)1(
0
)(
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 39
Derivative Mean-Value Theorem
(b-a)dx
df(ξf(a)f(b)
bhxax
(b-a)
f(a)f(b)
dx
df(ξ
baξ
)
,0,n TheoremTaylor Use:Proof
)
such that ],[point oneleast at exist then there
b)(a, intervalopen on the defined is derivativefirst its and
b][a, interval closed aon function continuous a isf(x) If
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 40
Alternating Series Theorem
termomittedFirst :
n terms)first theof (sum sum partial:
converges series The
0lim
S
series galternatin heConsider t
1
1
4321
4321
n
n
nnnn
a
S
aSS
andthen
a
and
aaaa
If
aaaa
Alternating Series is special case of Taylor Series.
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 41
Alternating SeriesExample 6
!7
1
!5
1
!3
11)1(s
!5
1
!3
11)1(s
0lim
since series galternatin convergent a is This!7
1
!5
1
!3
11)1(susingcomputed becansin(1)
4321
in
in
Then
aandaaaa
in
nn
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 42
Remark In this course all angles are assumed to
be in radian unless you are told otherwise
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 43
Maclurine series Find Maclurine Maclurine series expansion
of cos (x)
Maclurine series is a special case of Taylor series with the center of expansion c = 0
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 44
Taylor SeriesExample 7
∞xfor converges series The
....!6!4!2
1)(!
)0()cos(
0)0()sin()(
1)0()cos()(
0)0(')sin()('
1)0()cos()(
642∞
0
)(
)3()3(
)2()2(
∑
xxxx
k
fx
fxxf
fxxf
fxxf
fxxf
k
kk
)cos()( ofexpansion series MaclurineObtain xxf
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 45
Taylor SeriesExample 8
)!1(
12
)!1(
)5.0(
01.0)!1(
)5.0(
!
)5.0(...
!2
)5.0(5.01)(
:
2?x when0.01error truncationthatso)5.0exp()(
eapproximat toneeded is series Maclurine theof many terms How
11
15.01
22
nnError
xn
eErrorTruncation
xn
xxxf
Solution
xxf
nn
nn
nn
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 46
Taylor SeriesExample 8
432
384
1
48
1
8
1
2
11)(
0083.01667.0
43
)!1(
1
......
xxxxxf
boundError
n
trialBy
nError
Solution
EE 3561_Unit_1 (c)Al-Dhaifallah 1435 47
Summary Taylor series expansion is very important in
most numerical methods applications
approximation remainder
Remainder can be used to estimate approximation error or estimate the number of terms to achieve desirable
accuracy
1)1(n
0
)(
)()!1(
)()(
!
)()( ∑
nn
k
kk
cxn
fcx
k
cfxf