Midterm 2016 Corr
Midterm 2016 Corr
Midterm 2016 Corr
Question 2 The finite difference scheme approximates the derivative of a function as follows:
f .x C h/ f .x/
f 0 .x/
h
Knowing that h theoretically tends to 0, list possible issues that would emerge in floating-point arithmetics.
Answer 2 Round-off errors emerge as follows:
1. Loss of significance (fewer significant digits) due to the subtraction of similar numbers: f .x C h/ f .x/ when h small
2. Dividing by a small number h. See Gaussian elimination for instance.
Another source of error here is truncation error in the Taylor expansion with remainder of f .x C h/ where higher-order terms involving
powers of h were ignored. See chapter 6 of the lecture notes. An optimal h, compromise between the contradictory truncation and round-off
errors, can actually be found.
Question 4 Estimate the number of basic operations involved in calculating a polynomial of degree n at a point x:
p.x/ D a0 C a1 x C : : : C an x n
p.x/ D .: : : ..an x C an 1 /x C an 2 /x C : : : C a1 /x C a0
Answer 4 O.n2 / in the non-nested version versus O.n/ in the nested version.
Question 5 Within the Gaussian elimination approach, you decide to implement a stopping criterion through a tolerance ". Which stopping
criterion is a good choice?
Answer 5 No stopping criteria in Gaussian elimination as the method converges in a finite number of operations.
cos.sin.1=n/ C 1/
1
Question 7 Circle the correct answer: Apply Newtons method to h.x/ D 8x 8x 3 . Does Newtons iteration converge using the given initial
guess x1 D 0:5:
A. Yes, the iterations converge to x D 1.
B. Yes, although it does not converge to x D 1.
C. No, Newtons method diverges using this guess.
D. No, the iterations oscillate forever.
E. More information is needed to answer this question.
Answer 7 Answer B. [This question is ignored in the final grade unless you have the correct answer].
Question 8 Assume a decimal (base 10) floating-point machine able to store no more than 5 digits with an exponent range of 15. What is
the result of each of the following floating-point arithmetic operations?
1. 1 C 10 7
2. 1 C 104
3. 1010 C 104
4. 109 =10 7
5. 10 9 =10 7
Answer 8
1. 1
2. 10001
3. 1010
4. overflow
5. 10 2
56 55
Question 9 How many digits does the number 10 9 10 have?
Answer 9 2. Let us have a look at 0:1 9D 8:9. The other digits are leading 0 that are not considered as digits but stored in a power of 10
instead.
Question 10 True or false: If two real numbers are exactly representable as floating-point numbers, then the result of a real arithmetic
operation on them will also be exactly representable as a floating-point number.
Answer 10 False. See question 2.
Question 12 For a given floating-point number system, describe in words the distribution of machine numbers along the real line.
Answer 12 They are distributed logarithmically because of the powers of 10 (or 2 in a binary base) in their definition.
Question 13 Consider the following system of two equations in two variables .x; y/:
yx C x 3 D x
(
x2 C y 1D0
Completely define the solution space.
Answer 13 The first equation is the second equation multiplied by x. The solution space is thus defined by the second equation as x D 0 is
not always a solution, ie f.x; y/ j y D 1 x 2 g.
Question 14 Suppose we wish to compute the square root of a given positive number y. Provide the corresponding nonlinear equation to be
solved.
Answer 14 Solve in x the equation x 2 y D 0.
Question 15 In a floating-point system, what quantity determines the maximum relative error in representing a given real number by a
machine number?
Answer 15 mach
2
Exercise 1 [10 points]
Solve the linear system below by Gaussian elimination.
x1 x2 C 2x3 D 8
2x1 2x2 C 3x3 D 20
x1 C x2 C x3 D 2
Solution
Very basic. Not solved.
Solution
1. Error occurs when x is around 1, 1 and 0.
When x is around 0, that is when x is very small in absolute value, 1=.1 x/ is similar to 1=.1 C x/, and subtraction of similar
numbers is likely to give poor approximation.
When x is around 1 or 1, two issues may occur. First, dividing by a very small number may cause Overflow. Second, subtracting
a big number and a normal number may induce lost of accuracy.
2. Simply rearrange the expression into 2x=.1 x 2 /: the only remaining issue is potential Overflow when x is around 1 or 1.
Assuming that matrix A is invertible and that no row interchange is needed, adapt the Gaussian elimination technique to this system of
equations. Detail you reasoning and provide the algorithm (pseudo-code or Matlab language). [Skip the backward-substitution step]
Solution
The idea of this exercise was to simplify the Gaussian elimination procedure to the minimum number of required operations. The proposed
matrix A is said to be sparse as it stores many zeros. Algorithmically, it is useless to compute operations involving zeros and the Gaussian
elimination should thus be adapted accordingly. The algorithm simplifies as follows:
1: Input: A such that det.A/ 0
2: for j from 1 to n 1 do
3: i j C1
4: mult aij =ajj
5: aij 0
6: ai i ai i mult aj i
7: end for
Only one loop (counter j ) on the columns of A is needed. The usual i and k loops highly simplify here because of the structure of A.
3
Bonus [10 points]
You are given the number 112.2 in base b D 3. Translate it into base b D 2. Using base b D 10 is strictly prohibited (Assume you do not
know it).
Solution
As we did in class from the decimal base to the binary base, the idea in this exercise is to perform the needed operations in base 3. First, it was
important to note that 2 is base 3 is 2. Then:
Integer part:
112=2 D 21 C 0
21=2 D 10 C 1
10=2 D 1 C 1