Professional Documents
Culture Documents
MBE 2036
Quantifying Error
Part 3
Short review
Inflow
U
dH
Conservation law: U kH Eq 2.1 Water Tank
dt H Outflow
Mathematical model V=kH
U
(1 e k t ) H0e k t H Eq2.14
k
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
4
Inflow
1 1 U
= ln + = ln +
Water Tank
H Outflow
V=kH
1
ln Z t C Eq 2.7 U=15m/s
k H0=40m
k =0.5
1
ln Z0 Eqln2.8Z, 0 where Z 0 U kH0
1
CC EqZ2.8
where 0 U, kH 0
k k
Z may be larger or smaller than
Zero (mathematically). However,
Assign: = for this practical problem, Z must
be have the same sign with Z0.
1
dZ dH Eq
(Z02.5
=15-0.5x40<0)
k
(Z=15-0.5xH00 before stable)
1 dZ
k ) Z dt
(
In engineering problem, we know there must be a result. So,
we usually simplify the mathematics equations during the
Department of Mechanical solving process.
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
5
Short review
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
6
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
7
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
8
Increasing Precision
value
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
10
Significant Figures
The significant figures of a number are those digits that carry meaning
contributing to its precision. They are critical when reporting scientific
data because they give the reader an idea of how well you could actually
measure/report your data.
?
1 2 3 4 5cm
Ruler in centimeter
2.5 2.6
From the above ruler, I would estimate that the measurement ? would
be around 2.52cm.
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
11
Significant
A
Figures
1 2 3 4 5cm
Ruler in centimeter
2.5 2.6
From the above ruler, I would estimate that the measurement A would
be around 2.52cm.
However, some of you may say A is 2.51cm, 2.53cm or even 2.50cm
Basically, all of us would agree that A is at least 2.5cm. So, the first two
digits are certain digits and only the third digit which we have to estimate.
So, we could say that the above measurement has 3 significant figures
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
12
Significant Figures
49 48.3? 48.7? 48.8? 48.9?
48
Certain Approximation
We say it has 3 significant figures
We say it has 7
significant figures
873244
873244.3?
873244.4?
873244.6? 873245
An automobile speedometer and odometer
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
13
Significant Figures
We say the odometer has 7 significant figures
873244.3?
873244.4?
873244.6?
873244.6233582343903443
4.80 8 is exact
3 significant figures
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
14
True error
True Error = True value Approximation
The true error does not take into the account the order of
magnitude of the value under examination
Bridge Screw
True error
True Error = True value Approximation
The true error does not take into the account the order of
magnitude of the value under examination
Relative error
One way to overcome this problem is to normalize the
error to the true value, as in:
True value - Approxima tion
t 100% Eq 3.1
True value
t is the true percent relative error
Bridge Screw
Relative error
However, in many practical applications, it is not possible
to find the true value in advance.
One alternative is to normalize the error using the best
available approximation of the true value, i.e:
approximate error
a 100% Eq 3.2
approximation
The approximate percent relative error
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
18
Previous Present
approximation approximation True value
0 1 i i+1
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
19
0 1 i i+1
For such cases, the percent relative error can be determined according:
present approximat ion - previous approximat ion
a 100% Eq 3.3
present approximat ion
The approximate percent relative error
Question: when should PC stop calculating? Answer: The error is small enough
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8 20
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
22
1?
1 = 100 =?
1
Approximate N=1
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
23
1.5 1
a2 100% 33.3%
1.5
Approximate N=2
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
24
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
25
Number Approximation t% a%
of terms Result: e0.5
1 1 39.3 -
2 1.5 9.02 33.3
Since a is less
3 1.625 1.44 7.69
than s(0.05%),
4 1.645833333 0.175 1.27 the calculation
5 1.648437500 0.0172 0.158 stops
6 1.648697917 0.00142 0.0158
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
26
Round-off errors
in numerical computing
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
27
Round-off Errors
Digital computers have range and
precision limits on their ability to represent
numbers
Certain numerical manipulations are highly
sensitive to round-off errors. This can
result from both mathematical
considerations as well as from the way in
which computer perform arithmetic
operations.
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
28
Computer Representation of
numbers
2 7 0
1 6 8
3
0 9
4 5
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
29
Computer Representation of
numbers
Number system
Decimal : 86,409
Binary: 10101101
1 27 + 0 26 + 1 25 + 0 24
+ 1 23 + 1 22 + 0 21 + 1 20
= 173
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
30
Integer numbers
Representation of integer
Signed magnitude method: employs the first bit of a word to indicate the sign,
with a 0 for positive and a 1 for negative.
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
31
Integers numbers
Range of integers
Computer software uses fixed word size (number of bits)
to represent number.
16-bit integer can cover the range of integer from -32,768 to
32,767.
32-bit long integer can cover the range of integer from -
2,147,483,648 to 2,147,483,647
0
16-bit: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
32
0 denotes a positive
The mantissa is composed of the fraction (f) and
1 denotes a negative an implicit leading digit (1).
Department of Mechanical
Significant
and Biomedicaldigits baseexponent
Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
34
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
36
Example1
Example: considering the simplified floating point (+0.10002), try to convert it
into this format:
1. 2()
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
37
Example2
+0.2510 Implicit
leading bit
7+(-2)=5
0.01002= 1.00002 x 2-2 = 0 0101 0000
1.00002
1.10002
0.00112 = 1.1 x 2-3 = 0 0100 1000
7+(-3)= 4
0.187510
Note: Implicit leading bit is 1
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
38
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
40
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
41
Why shift?
Significant digits baseexponent
0.4 10 0 0.10 20
4 shifts to right 1.0 shifts to right
The mantissa has to shift right 1-(-3)=4 times 0.00011 This bit is outside the range limit
After expressing in the same exponent, the mantissas can then be added together:
= 1.10002 + 0.00012 = 1.10012 Compute the sum of aligned
mantissas
Therefore 310 + 0.187510 = 0 1000 1001
= 21 x (1 x 20 + 1 x 2-1 + 1 x 2-4)
= 3.125,
i.e error = 0.0625, Error% =0.0625*100/3.1875 =1.96%
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
44
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
45
ans =
2.220446049250313e-016
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
46
Summary
Computer represents numbers in a fixed word size. As a result, it limits
the range and precision that the computer/software can handle
numbers.
Normally, computer/software will provide single precision and double
precision format for handling numbers.
Double precision has bigger range and higher precision than single
precision format.
If the numbers is outside the range or precision limits of the single
precision format, double precision should be used.
Double precision occupies more computer memory and takes longer to
process. For small micro-processor systems, they may not be fast
enough to handle too many double precision floating point calculation.
Floating-point numbers cannot be represented exactly in computer. So,
if possible, use integer numbers for calculation.
Always make sure the number for arithmetic is bigger than the machine
epsilon.
Small errors can be accumulated to form a more significant error. So,
try to avoid performing large numbers of arithmetic operations on the
same variables.
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
48
Learning Outcomes
After this lecture, the student would be able to understand the
following:
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
49
Appendix
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
50
-Stopping criterion-
The following criterion assure that the result is correct to at
least n significant figures.
s (0.5 102n )% Eq 3.5
Proof: The stopping criterion is defined as:
1
| | < | | =
| |
When:
1 2
1
= 10 % = 10
2 2
We have:
1
1
10 Equation 1
| | 2
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
51
-Stopping criterion-
The following criterion assure that the result is correct to at
least n significant figures.
s (0.5 102n )% Eq 3.5
= 0. 10 (m is integer)
= 0. 1 2 10 (m is integer)
It is clear that: 0 10 0 10
So, we have:
1
1
1
10
10 | | 2
Or written as: 1
1 10 Equation 2
2
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
52
-Stopping criterion-
The following criterion assure that the result is correct to at
least n significant figures.
s (0.5 102n )% Eq 3.5
= 0. 10 (m is integer)
= 0. 1 2 10 (m is integer)
11.0010010000111111011010101000100010000101101000110000100011010011...
but is:
11.0010010000111111011011
when approximated by rounding to a precision of 24 bits.
3.1415927410125732421875.
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
54
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
55
Base-2 Base-10
2 2 21 2 0 2-1 2-2 2-3
101.101
= 4 + 0 + 1 + 0.5 + 0 + 0.125
= 5.625
Department of Mechanical
and Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing, part 3, Version 8
56
1.100011 x 22
Department of Mechanical
and Biomedical Engineering City University of Hong Kong