chapter2_computation_error
chapter2_computation_error
332
Intro to Numerical Analysis
x = 0.0; n = 0;
while x ~= 1.0 (“if x is not equal to 1.0”)
x = x + 0.1;
n = n + 1;
end
2.1 Floating-point numbers
Floating-point format for decimal numbers
Each decimal number is represented in a UNIQUE way as:
𝑥 = 𝜎 ⋅ 𝑥ҧ ⋅ 10𝑒
where
𝜎 = ±1 (the sign);
𝑒: an integer (exponent);
1 ≤ 𝑥ҧ < 10 (significand or mantissa)
1) 124.62
2) -0.0245
Examples
Write the following numbers in the binary format:
1) 𝑥 = 11011.0111 2
2) 𝑥 = −110.11001110011 2
IEEE floating-point formats for decimal numbers
𝑥 = 𝜎 ⋅ 𝑥ҧ ⋅ 2𝑒
𝑓 𝑥 = 𝑥2 + 1 − 1
(take x = 1e-8, 1e-9)
Loss of significance error
▪ Example: Consider the function
1 − cos(𝑥)
𝑓 𝑥 =
𝑥2
What should be a “good” approximate value of the above
function near x = 0?