Numerical Programming I (For CSE) : Final Exam
Numerical Programming I (For CSE) : Final Exam
Schraufstetter
WT 2009/10
February 5, 2010
General Instructions
Material: You may only use one hand-written sheet of paper (size A4, on both pages). All other material including electronic devices of any kind are forbidden. Exercise 1 (multiple choice) has to be solved directly on this sheet. For all the other exercises, use the exam paper that was handed out to write down your solution. It is recommendable to start a new page for every problem. Do not use a pencil, or red or green ink. General hint: In most cases, exercises b), c), etc. can be solved without the results from the previous exercise a): if you are stuck with exercise a), then dont immediately skip exercises b), c), etc. Show the solution steps in your answers and give reasons for your statements or conclusions (except the multiple choice part). Maximum score: The maximum score is 40 points plus a bonus of 3 points. Grades will be computed relatively to a maximum score of 40 points. Working time: 105 minutes. http://www.google.de/
exercise
5 http://www.google.de/
points
14
10
43
1) Multiple Choice
Which statements are correct? Remarks: For every question, there is at least one answer true.
( 4 + 3 = 7 points)
Mark true statements clearly with a cross (). If you wish to change your answer, cancel the wrong cross carefully ( ) so that your nal answer is in evidence. For every correct cross, you will get 0.5 points. For every wrong cross, 0.5 points will be discounted. If there isnt any cross, you will get 0 points. In a subtask, it is not possible to get negative points in total, i.e. if you have negative points in total in exercise a), this subtask will be rated with 0 points. Only mark a statement as true, if you are really sure! a) Part I Which statements about numerical algorithms are true? The absolute distance between two neighboring oating point numbers is not constant. The condition describes the sensitivity of a problem, concerning changes in the input data. An algorithm that is applied to a well-conditioned problem is always stable. The phenomenon of cancellation occurs, if two numbers with dierent sign and identical leading digits are added. How many operations have to be done in general when solving a triangular linear system of equations? O(n) O(n log n) O(n2 ) O(n3 ) When solving a system of linear equations Ax = b with the help of LU-factorization, pivoting should be used in order to . . . avoid division by zero, get a faster algorithm, reduce rounding errors and, thus, get a higher accuracy, improve the condition of the problem solve Ax=b. What has commonly much inuence on the behavior of convergence of the method of GauSeidel? the spectral radius of the iteration matrix, the greatest absolute eigenvalue of the system matrix, the right-hand side of the system, the resolution of the grid (if the linear system results from a partial dierential equation).
page 2 of 8
b) Part II Considering non-linear equations, which methods are only locally convergent? bisection method, regula falsi (false position method), secant method, Newtons method. Which of the following statements are true, when solving an ordinary dierential equation (ODE) numerically? To specify a solution of an ODE y (t) = f (t, y (t)) uniquely, initial values are needed. It holds: convergence + consistency stability. It holds: stability + consistency convergence. The Runge-Kutta method always leads to smaller errors than the method of Euler. If the local discretization error of a method for solving ordinary dierential equations converges towards 0 for increasingly smaller steps in time, then the method always is . . . convergent, consistent, stable, well-conditioned. Choose the best method in case of a sti problem! an explicit one-step method of higher order, e.g. Runge-Kutta, the mid-point rule, an implicit method, e.g. implicit Eulers method, an explicit multistep method, e.g. Adams-Bashforth method.
page 3 of 8
( 2 + 2 + 3 = 7 points)
Let f : R R be a mapping. The condition number for the evaluation f (x) is given by cond(f, x) := x f (x) . f (x)
a) Is the problem evaluate f at a point x > 0 for the function f (x) = well- or ill-conditioned? Why? b) Function (1) is evaluated with the following Matlab program: function y = stupidMethod(x) y = 1/(1+2*x) - 1; return; Why is the evaluation of stupidMethod not stable for all x > 0? Design another Matlab program smartMethod(x) that evaluates function (1), too, but is stable for all x > 0! c) Consider the function g (x, y ) = x2 y 2 that is evaluated with the following Matlab program: function z = g(x,y) z = x*x - y*y; return; Compute the relative rounding error e := that occurs when evaluating g. For which values (x, y ) R2 is the evaluation algorithm not stable? Why? g (x, y ) rd(g (x, y )) g (x, y ) 1 1. 1 + 2x (1)
page 4 of 8
3) Interpolation
Consider the function f : R R that is dened by f (x) = (x + 4)2 .
( 4 + 4 + 3 + 3 = 14 points)
a) Let p(x) be the polynomial interpolant of f with support points P0 = (x0 , y0 ), P1 = (x1 , y1 ), and P2 = (x2 , y2 ) and support abscissas x0 = 5, x1 = 3, x2 = 2.
Give an explicit representation of the interpolant p(x) by using divided dierences and Newtons interpolation formula
n1
(x xk ).
(2)
b) Now, let q (x) be the polynomial interpolant of f with support abscissas x0 = 2, Proove the estimation |f (x) q (x)| x1 = 1, 15 16 x2 = 1, x3 = 2.
x [2, 2].
Hint: Use a known formula for the interpolation error to show that [2, 2] : |f (x) q (x)| = 5 |x2 4| |x2 1| | + 4|6
holds, and nd estimations for the factors |x2 4|, |x2 1|, and | + 4|. c) Formulate a Matlab program function yp = eval newton(c,x,xp) that evaluates Newtons interpolation formula (2) with O(n) operations. The inputs of the function eval newton(c,x,xp) are denoted by c: a vector c = (c0 , . . . , cn ) with the divided dierences ci = [x0 , . . . , xi ]f , x: a vector x = (x0 , . . . , xn ) with the support abscissas xi , xp: a scalar x that denes the point of evaluation of p. The function returns the value yp that is a scalar y with the result of the evaluation y = p( x).
page 5 of 8
3) Interpolation (continued)
d) Now, the scheme of Aitken and Neville is applied to the support points 1 (x1 , y1 ) = ( , 1), 5 2 (x2 , y2 ) = ( , 2), 5 3 (x3 , y3 ) = ( , 1), 5 4 (x4 , y4 ) = ( , 2). 5
as illustrated in Fig. 1. What values do you get in the triangular scheme when evaluating the polynomials at x = 0? Sketch the triangular scheme shown below on your sheet and insert the correct values. You do not have to compute all the values with the formula, but you may use the plot of Fig. 1 which illustrates the four support points and the interpolants with support abscissas {x1 , x2 , x3 }, {x2 , x3 , x4 }, and {x1 , x2 , x3 , x4 }, respectively. All values of the triangular scheme are contained in Z.
1 5 2 5 3 5 4 5
x1 = x2 = x3 = x4 =
? ? ? ?
? ? ?
? ?
page 6 of 8
4) Numerical Quadrature
Consider the integral of a function f : [1, 1] R
1
( 2 + 3 + 1 + 4 = 10 points)
I (f ) :=
1
f (x) dx.
(3)
a) Which result do you get, when approximating integral (3) with the Simpson sum with n = 4 subintervals for f (x) = 3x2 1 ? b) Estimate the error |I (f ) QT S (f )| when approximating integral (3) with the trapezoidal sum x 2 QT S (f ) with 16 subintervals when f is given by f (x) = 1 2e . In general, when computing an integral numerically, the integral is approximated by a weighted sum
n
I (f )
i=0
gi f (xi ) =: Q(f ).
(4)
for polynomials p with a degree k as large as possible. c) Which degree of accuracy (max. polynomial degree) kmax can be achieved at most in case of n = 3 nodes, when the weights gi as well as the nodes xi can be chosen? d) Determine optimal weights and nodes g0 , g1 , and x0 so that the formula of quadrature Q(f ) := g0 f (x0 ) + g1 f (0) + g0 f (x0 ) (6)
is exact for all polynomials up to a degree k that is as large as possible, i.e. Eq. (5) holds for p(x) = xj , j = 0, 1, 2, . . . , k . Is this degree of accuracy k equal to the maximal possible degree of accuracy kmax of the general quadrature formula (4) for n = 3?
page 7 of 8
( 2 + 3 = 5 points)
a) The given Matlab code computes the LU factorization of a matrix A in situ. What does in situ mean? What does the algorithm return as result in detail? b) Find the LU factorization of the matrix 4 2 3 A = 2 2 1 . 2 2 2
page 8 of 8