Uploaded by W_work2016

02601ExamF2016 merged

advertisement
Tecnical University of Denmark
Written 4-hour exam, 19. May 2016
Course name: Introduction to Numerical Algorithms
Page 1 of 5
Course nr.: 02601
Aids and materials: All aids and materials permitted.
Weights: Multiple choice 25%, Question 1: 10%, Question 2: 15%, Question 3:
15%, Question 4: 20%, Question 5: 15%. The weight is only a guideline. The final
grade is based on overall assessment.
Multiple choice (25%)
Each question has only ONE correct answer. In your paper, you just need type the
number of the answer. You get 5% for a correct answer, 0% for no answer, and -2%
for a wrong answer.
A – Data-fitting. In a data-fitting problem we suppose to use the function F (x) =
P
n
j=0 cj φj (x) to fit the data points (xk , yk ) for k = 0, 1, 2, . . . , m with m > n. The
least-squares fit is defined as
Pm
2
1.
k=0 F (xk ) reaches the minimum.
Pm
2
2.
k=0 (yk − F (xk )) reaches the minimum.
3. F (x) is a quadratic function.
B – Interpolation. Consider the table
x −4 2 0 7
y −1 2 2 3
1. The table does not satisfy the condition to be an interpolation table that in
the table the values of x need be monotonically increasing.
2. The table does not satisfy the condition to be an interpolation table that in
the table there cannot be two points with the same y values.
3. The table satisfies the condition to be an interpolation table.
Page 1 of 5
C – Interpolation. Consider the table
x −1 2 2 3
y −4 2 0 7
1. The table does not satisfy the condition to be an interpolation table that in
the table the values of x can not be 0(zero).
2. The table does not satisfy the condition to be an interpolation table that in
the table there cannot be two points with the same x values.
3. The table satisfies the condition to be an interpolation table.
D – Numerical integration. The function f has the function values:
f (1) = 2,
f (2) = 2,
f (3) = 3.
(1)
R3
With three function values, the integral 1 f (x) dx can be approximated by using
the composite trapezoid rule and Simpson 1/3 rule. The integral also can be approximated by using the trapezoid rule with only two function values f (1) and f (3).
The three approximations I˜composite trapezoid , I˜Simpson and I˜trapezoid satisfy
1. I˜trapezoid < I˜composite trapezoid < I˜Simpson
2. I˜composite trapezoid < I˜Simpson < I˜trapezoid
3. I˜Simpson < I˜composite trapezoid < I˜trapezoid
4. I˜Simpson < I˜trapezoid < I˜composite trapezoid
E – Convergence of secant method. Consider a continuous and differentiable
function of one variable. With a starting point “close enough” to a simple root, the
convergence of secant method is
1. Linear.
2. Superlinear.
3. Quadratic.
Exercise 1. Newton’s method (10%)
In a data-fitting problem, we have found a trigonometrical function F fit the data,
which is defined as
F (x) = 26.77 − 40.49 sin(ωx) + 143.16 cos(ωx)
with ω = 2π/360.
In order to find the minimum of the function, we need find the root of its gradient
f (x) = F 0 (x) = −40.49ω cos(ωx) − 143.16ω sin(ωx).
(2)
1.1) Use Newton’s method to calculate the root x∗ for f . Set the starting point as
x0 = 120, run 4 iterations, and state the iterates x1 , x2 , x3 and x4 with 3 significant
digits.
Page 2 of 5
Exercise 2. Data-fitting (15%)
Suppose that we want to find the best function in the form
F (x) = a e−x + b e−2x
(3)
in the least-squares sense to fit the following data points
0
1
2
3
4
k
xk 0.0 0.5 1.0 1.5 2.0
yk 2.24 0.80 0.38 0.09 0.06
2.1) Set up the normal equation for calculating the coefficients a and b, and state
both the system matrix and the right-hand side in the normal equation.
2.2) Use Matlab to solve the normal equation, and state the solutions of a and b
with 4 decimal places.
2.3) Calculate the absolute error |yk − F (xk )| for k = 0, . . . , 4 and state them with
2 significant decimals.
Question 3. A Runge-Kutta method for solving an ordinary differential equation, theoretical question (15%)
All questions in this part can be answered independently to each other.
This question is about the numerical methods for solving initial-value problems.
The method considered here is called as RKvariant and is a Runge-Kutta method
of order 2, which was introduced in the lecture and the book.
K1 = f (t, x)
(4)
K2 = f (t + αh, x + βhK1 )
x(t + h) = x(t) + h ω1 K1 + ω2 K2
with
(5)
(6)
1
ω1 = ω2 = α = ,
β = 1.
(7)
2
Note that this method is different from the Heun’s method and midpoint method,
which had been practiced in the course. An implementation of Heun’s method that
is called as MyHeun is:
1
2
3
4
5
6
7
8
9
10
11
function [t,x] = MyHeun(dxdt,tspan,x0,n)
% [t,x] = MyHeun(dxdt,tspan,x0,n):
%
uses Heun’s method to integrate an ODE
% input:
%
dxdt = function handle to the rhs. of the ODE
%
tspan = [a, b] where a and b = initial and
%
final values of independent variable
%
x0 = initial value of dependent variable
%
n = number of steps
% output:
%
t = vector of independent variable
Page 3 of 5
12
13
14
15
16
17
18
19
20
21
22
23
24
25
%
x = vector of solution for dependent variable
a = tspan(1);
b = tspan(2);
t = (linspace(a,b,n+1))’;
h=(b-a)/n;
hhalve=h/2.0;
% beregner kun h/2 én gang
x = zeros(1,n+1);
% preallokere x det er hurtigere
x(1,1)=x0;
% lægger x0 som første x-værdi
for i = 1:n
% Heun’s method
K1=dxdt(t(i), x(1,i));
K2=dxdt(t(i+1), x(1,i)+h*K1);
x(1,i+1) = x(1,i) + (K2+K1)*hhalve;
end
3.1) State how to modify MyHeun in order to implement the method RKvariant.
You do not need to write a new Matlab function. Give the line number in order to
state the modifications clearly.
3.2) Do the constants ω1 = ω2 = α = 21 and β = 1 satisfy the condition that
the Runge-Kutta formula agrees with the Taylor expansion of x(t + h) up to and
including the term in h2 ? See the formula (9) in the book page 313. Explain your
answer.
3.3) Use the theory in the book to show that if the differential equation has the
form
dx
= f (x),
dt
where the right-hand side is only a function on x, then the RKvariant’s approximation agrees with the Taylor expansion of x(t + h) up to and including the term in
h2 .
3.4) Use the theory in the book to show that if the differential equation has the
form
dx
= g(t),
dt
where the right-hand side is only a function on t, then the RKvariant’s approximation agrees with the Taylor expansion of x(t + h) only up to and including the term
in h.
Question 4. A Runge-Kutta method for solving an ordinary differential equation, numerical experiments (20%)
In this question, you will study the numerical method RKvariant introduced in
Question 3 to solve initial-value problems. The Matlab function RKvariant is saved
in the same folder as the exam paper. This function is a p-file, i.e., it is a compiled
function and you cannot see the codes. It requires the same inputs and outputs as
the function MyHeun, which is given in Question 3.
The initial-value problem is
1
dx
= x,
dt
2
x(0) = 1.
Page 4 of 5
(8)
t
It has the analytical solution x(t) = e 2 . You do not need prove it.
4.1) Calculate the absolute errors of x(5) by solving the initial-value problem (8)
with RKvariant and n = 10, 20, 40, 80 and 160, respectively. The absolute errors
must be included in the answers.
4.2) Use the results from 4.1) to verify numerically that RKvariant has global
convergence of order O( n12 ) for solving the initial-value problem (8).
Consider the initial-value problem
dx
= cos(t),
dt
x(0) = 0.
(9)
It has the analytical solution x(t) = sin(t). You do not need prove it.
4.3) Calculate the absolute errors of x(5) by solving the initial-value problem (9)
with RKvariant and n = 10, 20, 40, 80 and 160, respectively. The absolute errors
must be included in the answers.
4.4) Use the results from 4.3) to verify numerically that RKvariant has global
convergence of order O( n1 ) for solving the initial-value problem (9).
Exercise 5: Sensitivity analysis (15%)
We consider two systems of linear equations
A x = b,
A x̃ = b̃,
b̃ = b + δb
(10)
where matrix A is a 100 × 100 matrix. We introduce δx = x̃ − x and the condition
number κ(A), and have
kbk2 = 1.4.
κ(A) = 2.2,
The absolute values of the elements in δb satisfy:
|δbi | ≤ 0.005,
i = 1, 2, . . . , 100.
(11)
5.1) Prove that
kδbk2 ≤ 0.05.
5.2) Derive the upper bound for the relative error kδxk2 /kxk2 in the solution.
End.
Page 5 of 5
(12)
Technical University of Denmark
Written 4-hour exam, 20 Dec. 2017
Page 1 of 4
Course name: Introduction to Numerical Algorithms
Course nr.: 02601
Aids and materials: All aids and materials permitted.
Weights: Multiple choice 30%, Question 1: 10%, Question 2: 15%, Question 3:
10%, Question 4: 20%, Question 5: 15%. The weight is only a guideline. The final
grade is based on an overall assessment.
Multiple choice (30%)
Each question has only ONE correct answer. In your paper, you just need type the
number of the answer. You get 5% for a correct answer, 0% for no answer, and -2%
for a wrong answer.
A – Errors. A number a is correctly rounded to 3.18 from a given number b. Then
|a − b| ≤ c, where c is
1. 0.005.
2. 0.01.
3. 0.18.
4. 0.09999.
B – Bisection method. Which of the following statements applies to the bisection
method used for finding roots of functions?
1. Can be used to find a root of a system of equations with several variables.
2. Require that functions need be continuous.
3. Is faster than the Newton’s method.
4. Require that the starting points are “sufficiently close” to a root.
Page 1 of 4
C – Numerical methods for solving ordinary differential equations. When
we use numerical methods to solve an ordinary differential equation, we try to approximate the curve of the solution. In which of the following methods, this curve
is approximated by the tangent in each interval?
1. Trapezoid method.
2. Euler’s method.
3. Newton’s method.
4. Runge-Kutta method.
D – Interpolation. Consider the interpolation table
x 0 15 18 22 30
y 22 24 37 25 143
If we are going to use quadratic interpolation, i.e. use a polynomial of degree 2 to
interpolate, to find the value of y at x = 14.9, which selection of nodes shown in the
following would be the optimal for interpolation?
1. 0, 15, 18, 22.
2. 15, 18, 22, 30.
3. 15, 18, 22.
4. 0, 15, 30.
E – Condition number. The condition number of a matrix A is used to
1. speed up pivoting.
2. determine how many steps pivoting takes.
3. determine the relation between error in A and error in b.
4. estimate the sensitivity of the solution to the error in b.
F – Solving linear system. For a given 2000-by-2000 matrix A, assume that it
takes about 15 seconds to find the inverse of A by the use of the LU factorization,
that is, calculating LU factorization once, and then doing forward substitution and
back substitution 2000 times using the 2000 columns of the identity matrix as the
right hand side vector. The approximate time, in seconds, that it will take to find the
inverse of A by repeated use of Naive Gaussian Elimination method, that is, doing
Gaussian elimination and back substitution 2000 times by using the 2000 columns
of the identity matrix is
1. 300.
2. 1500.
3. 7500.
4. 30000.
Page 2 of 4
Question 1. Interpolation (10%)
1.1) Derive the polynomial p(x) of the lowest degree that interpolates the function
f (x) = ln x at the nodes x = 1, 2, 3.
1.2) Determine an upper bound for the absolute interpolation error |f (x) − p(x)| on
the interval [1, 3].
Question 2. Data fitting (15%)
Suppose that we want to find the best function in the form
f (x) = a sin(πx) + b cos(πx) + c
in the least-squares sense to fit the following data points
x −1 − 12
y −1 0
0 12 1
1 2 1
2.1) Set up the normal equation for calculating the coefficients a, b and c, and state
both the system matrix and the right-hand side in the normal equation.
2.2) Use Matlab to solve the normal equation, and state the solutions of a, b and c
with 4 significant digits.
2.3) Plot the absolute error |yk − f (xk )| for k = 0, 1, 2, 3, 4 and state the maximum
of the absolute error with 2 decimal places.
Question 3. Numerical integration (10%)
Estimate the value of the integral
Z
3
x ln x dx
1
by using the composite Simpson’s 1/3 rule.
3.1) Find the number of subintervals n such that the absolute error is guaranteed
to not exceed 10−4 .
3.2) Compute this integral by using the composite Simpson’s 1/3 rule with n obtained in the former question. You will need the Matlab function MySimpson.m,
which is saved in the same folder as the exam paper, or you can use your own
implementation. Show the result with 5 significant digits.
Question 4. Newton’s method (20%)
Consider the function f (z) = z + |z|2 − 2z − 3iz 2 with a complex variable z, where
i2 = −1. We want to find a complex number z such that f (z) = 4 + i.
4.1) Assume z = x1 +x2 i and set up a system of the nonlinear equations, F (X) = 0,
with the variable X = [x1 , x2 ]T according to the fact that the real part and the
imaginary part of f (z) equal 4 and 1, respectively. Write down the two nonlinear
equations.
Page 3 of 4
4.2) Derive and state the Jacobian matrix F 0 (X).
4.3) Apply Newton’s method to solve the system of the nonlinear equations. Run
5 iterations with the initial guess X0 = [1, 1]T . Which root does Newton’s method
converge to? State the solution with 4 significant digits. Include Matlab code in
your paper.
4.4) Save the last iterate as X ∗ , and for each iteration calculate the maximum
absolute error, which is defined as:
(k)
ek = max |x∗i − xi | ,
k = 1, 2, 3, 4,
1≤i≤2
(k)
(k)
where X (k) = [x1 , x2 ]T . Plot ek with the Matlab function semilogy. Which
convergent rate does ek show? How do you find it?
Question 5. Initial-value problem (15%)
A planet is orbiting around a star. With a suitable (x, y)-coordinate system centered
on the star, the motion will be in the plane. A simplified model for the position
(x(t), y(t)) (in normalized units) of the center of mass of the planet over time, is
given by the ordinary differential equations
x00 (t) = −
x
(x2 + y 2 )
3
2
,
y 00 (t) = −
y
.
(1)
y 0 (0) = 2.
(2)
3
(x2 + y 2 ) 2
The initial conditions are
x(0) = 0.4,
y(0) = 0,
x0 (0) = 0,
5.1) We introduce the new variables z1 = x, z2 = y, z3 = x0 , and z4 = y 0 . Rewrite
the initial-value problem (1) and (2) into a system of first-order differential equations
in the variables Z = [z1 , z2 , z3 , z4 ]T .
5.2) Write down the calculation of an approximate value Z(0.2) for this initial value
problem by taking two steps of Euler’s method with step size h = 0.1, and state the
result with 4 significant digits.
5.3) Apply the Runge-Kutta method of order 4 to solve this system of differential
equation with the interval [0, 2π] and n = 50, i.e., h = 2π
50 . You will need the Matlab
function MyRK4System.m, which is saved in the same folder as the exam paper, or
you can use your own implementation. Show the plot (xi , yi ), i.e. ((z1 )i , (z2 )i ),
i = 0, · · · , n.
End.
Page 4 of 4
Tecnical University of Denmark
Written 4-hour exam, 15. May 2017
Course name: Introduction to Numerical Algorithms
Page 1 of 5
Course nr.: 02601
Aids and materials: All aids and materials permitted.
Weights: Multiple choice 25%, Question 1: 20%, Question 2: 25%, Question 3:
15%, Question 4: 15%. The weight is only a guideline. The final grade is based on
overall assessment.
Multiple choice (25%)
Each question has only ONE correct answer. In your paper, you just need type the
number of the answer. You get 5% for a correct answer, 0% for no answer, and -2%
for a wrong answer.
A – Data-fitting. Suppose that we want to use the function
y = a ln(x) + b exp(−x) + c x
to fit the data points (xi , yi ), i = 0 . . . , 14. Considering the least-square fit, the
system matrix of the normal equation has
1. 14 rows and 3 columns.
2. 15 rows and 3 columns.
3. 15 rows and 15 columns.
4. 3 rows and 3 columns.
5. The function is not linear on the coefficients, so we cannot formulate the normal
equation.
B – Gaussian elimination with partial pivoting. Using Gaussian elimination
with partial pivoting on the matrix


1 4 5
A= 2 3 6 
3 0 1
we will make the following changes on the rows:
1. It’s not necessary to interchange any rows.
2. Interchange row 1 with row 3.
3. Interchange row 1 with row 3, then interchange row 2 with row 3.
4. Cannot run Gaussian elimination on the matrix A.
Page 1 of 5
C – Sensitivity analysis for the solution to a system of linear equations.
Considering a system of linear equations Ax = b, we know that kAk2 = 7, kA−1 k2 =
3, and without data error kbk = 10. To ensure the relative error in the solution
kδxk
kxk < 0.01, the absolute data error kδbk is at most as large as approximately:
1. The largest value of kδbk cannot be calculated, since kxk is unknown.
2. kδbk = 0.030.
3. kδbk = 0.0033.
4. kδbk = 0.043.
5. kδbk = 0.0048.
D – Numerical integration. Consider the function f (x) = xex on the interval I =
[−3; 1]. Apply
approximate
R 1 the composite trapezoid rule on n equal subintervals to
(m)
the integral −3 f (x) dx. We know that the mth derivative of f is f (x) = (m +
x)ex ≤ (m + 1)e in the interval I. What is the smallest value n such that the largest
approximation error is 10−4 ?
1. n = 842
2. n = 660
3. n = 76
4. n = 30
5. n = 18
E – Convergence of Newton’s method. Consider a continuous and twice continuous differentiable function of one variable. With a starting point “close enough”
to a simple root, the convergence of Newton’s method is
1. Linear.
2. Superlinear.
3. Quadratic.
4. O( n12 ), where n is the number of iterations.
Page 2 of 5
Question 1. Data-fitting (20%)
Suppose that we want to fit a periodic but noisy signal by a function
F (x) = a cos(x) + b sin(x) + c cos(2x) + d sin(2x).
(1)
The data can be found in Opgave1Data.mat, which is saved in the same folder as
the exam paper.
1.1) Set up the normal equation for calculating the coefficients a, b, c and d, and
state both the system matrix and the right-hand side in the normal equation.
1.2) Use Matlab to solve the normal equation, and state the solutions of a, b, c and
d with 4 significant digits.
1.3) Calculate the sum of the absolute error |yk − F (xk )| for k = 1, . . . , 35 and state
it with 3 decimal places.
1.4) Now we want to use the fit function in the same form as (1) to fit several
different data sets. For each data set, the x-values are the same, but the y-values
are different, so we will obtain different a, b, c and d by solving the corresponding
normal equation. Can we use the factorization on the system matrix of the normal
equation to speed up the process? Explain why?
Question 2: Approximation of a function (25%)
In this question, we will approximate the function f (x) = xex on the interval
I = [−3, 1] and study the approximation error. Obviously we know that the nth
derivative of f is f (n) (x) = (n + x)ex .
2.1) Based on the second interpolation error theorem, how accurate will the interpolation be, if we use a polynomial of degree at most 8, named as p8 , on 8+1 equally
spaced nodes to approximate the function f ?
2.2) Test numerically by taking 300 equally spaced points in the interval I and plot
the error f (x) − p8 (x). Include the plot in your paper. For this question, you will
need the Matlab function InterpolerLagrangeForm.m, which is saved in the same
folder as the exam paper, or you can use your own implementation.
2.3) Compute and state the maximum absolute error maxx∈I |f (x) − p8 (x)| in these
300 points in Question 2.2.
Now we approximate f by a polynomial of degree at most 20, p20 , on 20 + 1 equally
spaced nodes in the interval I.
2.4) Compute and state the maximum absolute error maxx∈I |f (x)−p20 (x)| in these
300 points as in Question 2.2.
2.5) Note that the results of Question 2.4 is larger than the theoretical upper bound
given in the second interpolation error theorem. Explain why this can happen?
Page 3 of 5
Question 3. A Runge-Kutta method for solving an ordinary differential equation (15%)
This question is about the numerical methods for solving initial-value problems. The
method considered here is a Runge-Kutta method of order 2, which was introduced
in the lecture and the book,
K1 = f (t, x)
(2)
K2 = f (t + αh, x + βhK1 )
x(t + h) = x(t) + h ω1 K1 + ω2 K2
(3)
(4)
with
2
ω1 = ,
5
ω2 =
3
5
and
5
α=β= .
6
(5)
An implementation of a Runge-Kutta method of order 2 is named as MyHeun, which
had been used in our course:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function [t,x] = MyHeun(dxdt,tspan,x0,n)
% [t,x] = MyHeun(dxdt,tspan,x0,n):
%
uses Heun’s method to integrate an ODE
% input:
%
dxdt = function handle to the rhs. of the ODE
%
tspan = [a, b] where a and b = initial and
%
final values of independent variable
%
x0 = initial value of dependent variable
%
n = number of steps
% output:
%
t = vector of independent variable
%
x = vector of solution for dependent variable
a = tspan(1);
b = tspan(2);
t = (linspace(a,b,n+1))’;
h=(b-a)/n;
hhalve=h/2.0;
% beregner kun h/2 én gang
x = zeros(1,n+1);
% preallokere x det er hurtigere
x(1,1)=x0;
% lægger x0 som første x-værdi
for i = 1:n
% Heun’s method
K1=dxdt(t(i), x(1,i));
K2=dxdt(t(i+1), x(1,i)+h*K1);
x(1,i+1) = x(1,i) + (K2+K1)*hhalve;
end
3.1) State how to modify MyHeun in order to implement the method with (2)-(4),
i.e. ω1 = 52 , ω2 = 35 and α = β = 56 . You do not need to write a new Matlab
function. Give the line number in order to state the modifications clearly.
3.2) Show that the Runge-Kutta formula with ω1 = 52 , ω2 = 35 and α = β =
agrees with the Taylor expansion of x(t + h) up to and including the term in h2 .
Page 4 of 5
5
6
Question 4: A boundary-value problem (15%)
In this question, we will solve a boundary-value problem
x00 (t) = x0 (t) − t x(t),
x(0) = 0,
x(2.5) = 1.
(6)
4.1) Rewrite the equation x00 (t) = x0 (t) − t x(t) as a system of first-order differential
equation, and implement a Matlab function to return the right-hand side of the
system. Include the Matlab code in your paper.
4.2) Use the Matlab function ode45 with the default setting to solve the initial-value
problem x(0) = 0 and x0 (0) = 1 with the differential equation x00 (t) = x0 (t) − t x(t)
in the interval t ∈ [0, 2.5]. Include a figure of (t, x(t)) for t ∈ [0, 2.5] and verify that
x(2.5) equals approximately 1.94.
Show that the function x(t) = 0 for t ∈ [0, 2.5] solves the initial-value problem
x(0) = 0 and x0 (0) = 0 with the differential equation x00 (t) = x0 (t) − t x(t). So now
you know two solutions starting at x(0) = 0 with different slopes at this point.
4.3) Find a slope z such that the initial-value problem x(0) = 0 and x0 (0) = z solves
the boundary-value problem (6).
End.
Page 5 of 5
Tecnical University of Denmark
Written 4-hour exam, 19. Decemeber 2018
Course name: Introduction to Numerical Algorithms
Page 1 of 5
Course nr.: 02601
Aids and materials: All aids and materials permitted.
Weights: Multiple choice 25%, Question 1: 10%, Question 2: 20%, Question 3:
15%, Question 4: 10%, Question 5: 20%. The weight is only a guideline. The final
grade is based on overall assessment.
Multiple choice (25%)
Each question has only ONE correct answer. In the pdf file with your answers, you
just need type the number of the answer. You get 5% for a correct answer, 0% for
no answer, and -2% for a wrong answer.
A – Gaussian elimination with partial pivoting. The reason for always performing partial pivoting in Gaussian elimination is:
1. It reduces the computational complexity by a factor 2.
2. We must make sure that the largest element in the solution to A x = b lies in
the first element in x.
3. We must avoid that the solution has a large rounding error due to e.g. loss of
significance.
4. To make sure that the matrix A has the full rank.
B – Interpolation. Consider the table
x 0
3 3 5
y −2 −2 0 9
1. The table does not satisfy the condition to be an interpolation table because
the values of x can not be 0 (zero).
2. The table does not satisfy the condition to be an interpolation table because
the values of x must be equally spaced.
3. The table does not satisfy the condition to be an interpolation table because
there cannot be two points with the same y values.
4. The table does not satisfy the condition to be an interpolation table because
there cannot be two points with the same x values.
5. The table satisfies the condition to be an interpolation table.
C – Convergence of the secant method. Consider a continuous and differentiable function of one variable. With a starting point “close enough” to a simple
root, the convergence of secant method is
Page 1 of 5
1. Linear.
2. Superlinear.
3. Quadratic.
4. Something else.
D – Sensitivity analysis. We consider two systems of linear equations
A x = b,
A x̃ = b̃,
b̃ = b + δb.
(1)
where A is a 100 × 100 matrix that is invertible. We set δx = x̃ − x, the condition
number of A is denoted by κ(A), and we have
κ(A) = 5.3,
kbk2 = 1.4,
x = [1, −1, 1, −1, · · · ].
If the absolute error δb satisfies:
kδbk2 ≤ 0.07,
(2)
we obtain the upper bound for the relative error kδxk2 /kxk2 in the solution as
1. 0.371.
2. 0.265.
3. 2.65.
4. 7.42.
E – Numerical integration. Consider the function f (x) = xex on the interval
I = [0, 4]. Apply the composite
R 4 Simpson’s rule on n equally spaced subintervals
to approximate the integral 0 f (x) dx. We know that the mth derivative of f is
f (m) (x) = (m + x)ex . What is the smallest value n such that the largest approximation error is guaranteed to not exceed 10−4 ?
1. n = 71
2. n = 2090
3. n = 72
4. n = 84
Page 2 of 5
Question 1: Gaussian elimination with partial pivoting (10%)
We have the following system of linear equations:
2x + 4y + 5z =13
3x + 6y − 3z =9
x − 2y + 8z =4.
Apply Gaussian elimination with partial pivoting to solve this linear system. This
question does not need use Matlab. The derivations, intermediate results and explanations should be included in the pdf file with your answers.
1.1) State the final upper triangular matrix and the elimination coefficient in each
step.
1.2) Use back substitution to obtain the solution of this linear system and state the
solution.
Question 2. Data-fitting (20%)
Suppose that we want to fit the data (xk , yk ), k = 0, · · · , 25, by a function of the
form
F (x) = a + b x + c cos(3x) + d ex .
(3)
The data can be found in data.mat, which is saved in the same folder as the exam
paper.
2.1) Set up the normal equation for calculating the coefficients a, b, c and d, and
state both the system matrix and the right-hand side in the normal equation.
2.2) Use Matlab to solve the normal equation, and state the solutions of a, b, c and
d with 4 significant digits.
2.3) Use Matlab to calculate the sum of the absolute error |yk − F (xk )| for k =
0, . . . , 25 and state it with 3 decimal places.
2.4) Now we want to use the function F (x) in (3) to fit several different data sets.
For each data set, the x-values are the same, but the y-values are different, so we
will obtain different a, b, c and d by solving the corresponding normal equation.
Can we use the factorization of the system matrix of the normal equation to speed
up the process? Explain your answer.
Question 3: Newton’s method for a system of nonlinear equations
(15%)
Consider a system of nonlinear equations F (X) = 0 with
#
"
# "
x21 + x22 − 6x1 − 2x2 + 1
f1 (x1 , x2 )
x1
.
X=
and
F (X) =
=
x2
f2 (x1 , x2 )
4x21 + 9x22 − 8x1 + 18x2 − 23
We use Newton’s method to find the solution which is the most distant from the
origin.
3.1) Derive the Jacobian matrix F 0 for the vector function F , and write a Matlab
function funFdF 1 starting with:
Page 3 of 5
[F,dF] = funFdF 1(X)
It returns a vector F with the values of F (X) and a matrix dF with the values of
the Jacobian matrix F 0 (X). Include your Matlab code in the pdf file with your
answers.
3.2) State a starting point X (0) that gives the solution which is the most distant
from the origin, and explain how you chose it. (Hint: In Matlab, ezplot is a
function plotter. Example: You can easily plot the equation xy − 2x + 1 = 0 by
calling ezplot(’x*y - 2*x + 1’).)
3.3) Run 10 iterations of Newton’s method with the starting point X (0) from Question 3.2, and state your final solution X (10) . For this question, you will need the
Matlab function Newtonsys.m, which is saved in the same folder as the exam paper.
Question 4. Polynomial approximation of a function (10%)
In this question, we will approximate the function f (x) = (x + 3)ex on the interval
I = [0, 6] and study the approximation error. We know that the mth derivative of
f is f (m) (x) = (x + 3 + m) ex .
4.1) Based on the second interpolation error theorem, how accurate will the interpolation be, if we use a polynomial of degree at most 16, named as p16 , on 16 + 1
equally spaced nodes to approximate the function f over I?
4.2) Test numerically by taking 300 equally spaced points in the interval I and plot
the error f (x) − p16 (x). Include the plot in the pdf file with all your answers. For
this question, you will need the Matlab function LagrangeFormInterpolation.m,
which is saved in the same folder as the exam paper, or you can use your own
implementation.
Question 5: Initial-value problem (20%)
We consider the initial-value problem
x00 = x2 − y + et
y 00 = x − y 2 − et
(4)
0
x(0) = 0,
x (0) = 0
y(0) = 1,
y 0 (0) = −2
5.1) We introduce the new variables z1 = x, z2 = y, z3 = x0 , and z4 = y 0 . Rewrite
the problem (4) into a system of first-order differential equations in the variables
Z = [z1 , z2 , z3 , z4 ]T , and state the initial condition for Z at t = 0.
5.2) Implement a Matlab function that returns the right-hand side of the system
for Z. Include your Matlab code in the pdf file with your answers.
5.3) Apply the Runge-Kutta method of order 4 to solve this system of differential
equation in the interval [0, 2]. Use h = 2−k with k = 4 and 5.
• State the number of steps n and the number of function evaluations nf for
k = 4 and 5, respectively.
Page 4 of 5
• State the results of (x(2), y(2)) at t = 2 for k = 4 and 5, respectively.
You will need the Matlab function MyRK4System.m, which is saved in the same folder
as the exam paper, or you can use your own implementation.
End.
Page 5 of 5
Tecnical University of Denmark
Written 4-hour exam, 18. Decemeber 2019
Course name: Introduction to Numerical Algorithms
Page 1 of 4
Course nr.: 02601
Aids and materials: All aids and materials permitted.
Weights: Multiple choice 25%, Question 1: 10%, Question 2: 15%, Question 3:
15%, Question 4: 15%, Question 5: 20%. The weight is only a guideline. The final
grade is based on overall assessment.
Multiple choice (25%)
Each question has only ONE correct answer. In the pdf file with your answers, you
just need to indicate the number of your answer. You get 5% for a correct answer,
0% for no answer, and −2% for a wrong answer.
A – Errors. A number A is correctly rounded to 3.18 from a given number B.
Then |A − B| ≤ C, where C is
1. 0.005
2. 0.010
3. 0.180
4. 0.09999
B – Interpolation: Lagrange form. Consider the table
x 15 18 22
y 24 37 25
The Lagrange form of the interpolation polynomial that interpolates the three data
points is given by
p2 (x) = l0 (x) · 24 + l1 (x) · 37 + l2 (x) · 25.
The value of l1 (x) at x = 16 is
1. −0.071430
2. 0.50000
3. 0.57143
4. 4.3333
C – Interpolation: error theorem. We approximate the function f (x) = e5x by
a polynomial of degree at most n with n + 1 equally spaced points on the interval
[0, 2], and we name this polynomial as pn . The k-th derivative of f is given by
f (k) (x) = 5k e5x . Based on the second interpolation error theorem, what is the
smallest n such that the approximation error |f (x) − pn (x)| ≤ 10−6 for all x ∈ [0, 2]?
Page 1 of 4
1. 21
2. 22
3. 23
4. 24
D – Secant method. To use the secant method finding the root of sin(x) = 0,
which of the following choice of initial guesses would NOT be appropriate?
1.
π
4
and
π
2
2.
π
4
and
3π
4
3. − π2 and
4.
π
3
and
π
2
π
2
E – Runge-Kutta method. Using the fourth-order Runge-Kutta method with the
step size h = 0.25 to solve an initial values problem, we obtain the global truncation
error of order 10−2 . If we want to have the error of order 10−6 , which size of h
should we choose:
1. h ≈ 0.05
2. h ≈ 0.025
3. h ≈ 0.005
4. h ≈ 0.0396
Question 1: Integration (10%)
Compute an approximate value for the integral
Z π
2
sin(2x)dx
(1)
0
by using the composite Simpson’s rule.
1.1) In the composite Simpson’s rule, the interval [0, π2 ] is subdivided into n equally
spaced subintervals with n an even integer. According to the error term for the
composite Simpson’s rule, find a condition on n such that the approximation of the
integral (1) has an absolute error less than 10−6 . State your result as an inequality
for n.
1.2) Use the smallest n, which satisfies the condition obtained in Question (1.1),
in the composite Simpson’s rule to compute the approximation of (1). State your
results on n and the approximated integral value. For this question, you will need
the Matlab function MySimpson.m, which is saved in the same folder as this exam
assignment.
Page 2 of 4
Question 2. Data-fitting (15%)
We need to compute a least-squares fit to the following data:
k
xk
yk
0
−1
−1
1
− 12
0
2
0
1
3
1
2
2
4
1
1
The fit function is of the form
f (x) = a sin(πx) + b cos(πx).
2.1) Set up the normal equation
AT Ac = AT y
(2)
with c = [a, b]T for the least-squares fit. Use Matlab to compute the coefficients a
and b, and state the solutions of a and b with 2 decimal places.
2.2) Use Matlab to calculate the sum of the absolute errors:
4
X
|yk − f (xk )|,
k=0
and state it with 3 significant digits.
2.3) We now consider the normal equations (2). If instead of the data y = [y0 , y1 , y2 , y3 , y4 ]T
we have a perturbed data ỹ, and the relative error in the right-hand side of the normal equation satisfies
kAT ỹ − AT yk2
≤ 0.01.
kAT yk2
What is the upper bound on the relative error in the solution c?
Question 3: Newton’s method (15%)
Consider a graph given by y = x2 . Use Newton’s method to find the value of x
that produces the point on the graph with the smallest Euclidean distance to (1, 0).
(Hints: 1. Minimize d(x)2 , where d(x) represents the Euclidean distance from (x, x2 )
to (1, 0); 2. Newton’s method can be used to find a minimizer of a function F by
finding a root for F 0 ).
3.1) Derive the nonlinear equation for obtaining x that produces the point on the
graph with the smallest Euclidean distance to (1, 0).
3.2) Write the formula of Newton iteration for solving your nonlinear equation from
Question (3.1).
3.3) Set the starting point x0 = 1, run 4 Newton iterations, and state the iterates
x1 , x2 , x3 and x4 with 3 significant digits.
Page 3 of 4
Question 4. Cholesky factorization (15%)
4.1) Assume that the matrix A has the size n × n and is non-singular. Which
condition should A satisfy such that it has a Cholesky factorization A = LLT ?
4.2) Now we consider the linear system A2 x = b, where the matrix A satisfies the
condition for having Cholesky factorization. We solve this linear system with two
strategies below. Determine the dominating term in the number of Long Operations
(LOps) for both strategies. Which strategy has the smaller dominating term?
• Strategy 1: Calculate the matrix M = A2 , then use Cholesky factorization
of M to solve M x = b. Note that the computation of A2 costs n3 LOps.
• Strategy 2: Calculate Cholesky factorization of A, then use it to solve the
system A2 x = b.
Question 5: Boundary-value problem (20%)
We consider the boundary-value problem
x00 (t) + 4x0 (t) + 4x(t) − e−2t = 0
x(0) = 1,
(3)
x(2) = 0
5.1) Rewrite the problem (3) as a system of first-order differential equations, and
implement a Matlab function to return the right-hand side of the system. Include
the Matlab code in the pdf file with your answers.
5.2) Use the Matlab function ode45 with the default setting to perform two “shootings” for the ordinary differential equation (3) with the initial conditions
x(0) = 1,
x0 (0) = z = −1
and
x(0) = 1,
x0 (0) = z = −5,
respectively. State the values of x(2) in these two shootings.
5.3) In the shooting method, we consider the value of x at the end point, i.e., x(2),
as a function ϕ(z) of z and z = x0 (0). Based on the answers in Question (5.2), you
have two points on the curve (z, ϕ(z)). Use one iteration of the secant method on
the equation ϕ(z) = 0 to calculate a new iterate ẑ. State the value of the new ẑ,
and perform a new shooting for the ordinary differential equation (3) with the initial
condition
x(0) = 1, x0 (0) = ẑ.
Include a plot of the new shooting (t, x(t)) for t ∈ [0, 2] in your answer.
End.
Page 4 of 4
Tecnical University of Denmark
Written 4-hour exam, 17. Decemeber 2020
Page 1 of 4
Course name: Introduction to Numerical Algorithms
Course nr.: 02601
Aids and materials: All aids and materials permitted.
Weights: Question 1: 20%, Question 2: 20%, Question 3: 20%, Question 4: 10%,
Question 5: 10%, Question 6: 20%. The weight is only a guideline. The final grade
is based on overall assessment.
Question 1: Approximation of a function (20%)
In this question, we will approximate the function f (x) = ln x on the interval I =
[1, 2] and study the approximation error. We know that the absolute value of the
nth derivative of f is |f (n) (x)| = (n−1)!
for n > 1.
xn
1.1) Approximate the function f (x) by an interpolation polynomial of degree 9,
named p9 , on 9 + 1 equally spaced nodes in the interval I with the first point at
x = 1 and the last point at x = 2. Compute and state the maximum absolute error
maxx∈I |f (x)−p9 (x)| at 400 equally spaced points in the interval I. For this question,
you will need the Matlab function InterpolerLagrangeForm.m, which is saved in
the same folder as the exam assignment, or you can use your own implementation.
1.2) Based on the second interpolation error theorem, find a theoretical upper bound
of the interpolation error for p9 . State this upper bound. (Hint: The factorial n!
can be calculated by using the Matlab function factorial(n).)
Now we approximate f by a polynomial of degree 25, p25 , on 25 + 1 equally spaced
nodes in the interval I.
1.3) Compute and state the maximum absolute error maxx∈I |f (x)−p25 (x)| in these
400 points as in Question 1.1.
1.4) Note that the result in Question 1.3 is larger than the theoretical upper bound
given in the second interpolation error theorem. Is there an error in the theoretical
upper bound or is there another explanation?
Question 2. Data-fitting (20%)
We need to compute a least-squares fit to the following data:
k
xk
yk
0
-2
0
1
-1
15
2
0
25
3
1
50
4
2
110
The fit function is of the form
F (x) = a + bx + c(x2 − 1)
2.1) Let y = [y0 , · · · , y4 ]T and c = [a, b, c]T . Set up the normal equation
AT Ac = AT y
Page 1 of 4
(1)
for the least-squares fit. State both the system matrix and the right-hand side in
the normal equation.
2.2) Use Matlab to solve the normal equation, and state the solutions of a, b and c
with 3 significant digits. Include the Matlab code in the pdf file with your answers.
2.3) Let F = [F (x0 ), · · · , F (x4 )]T . Use Matlab to calculate the absolute error
ky − F k2 with the 2-norm of a vector, and state it with 2 decimal places.
2.4) We now consider the normal equation (1). Now instead of the data y we have
a perturbed data ỹ, and the relative error in the right-hand side of the normal
equation satisfies
kAT ỹ − AT yk2
≤ 0.01.
kAT yk2
What is the upper bound on the relative error in the solution c?
Question 3: Solving a system of nonlinear equations (20%)
Consider a system of nonlinear equations F (X) = 0 with
x
X= 1
x2
and
F (X) =
"
#
f1 (x1 , x2 )
f2 (x1 , x2 )
"
=
x21 + 2x2 − 2
#
x1 + 4x22 − 4
.
We use Newton’s method to find a solution with a given starting point.
3.1) Derive the Jacobian matrix F 0 for the vector function F , and write a Matlab
function funFdF starting with:
function [F, dF] = funFdF(X)
The function should return a vector F with the values of F (X) and a matrix dF
with the values of the Jacobian matrix F 0 (X). Include your Matlab code in the pdf
file with your answers.
3.2) Write the formula of Newton iteration for solving the nonlinear equations
F (X) = 0.
3.3) Run 8 iterations of Newton’s method with the starting point X (0) = [1, 2]T ,
and state your final solution X (8) . For this question, you will need the Matlab
function Newtonsys.m, which is saved in the same folder as the exam assignment.
3.4) Save the last iterate as X ∗ , and for each iteration calculate the 2-norm of the
absolute error, which is defined as:
ek = kX (k) − X ∗ k2 ,
for k = 1, 2, · · · , 7.
Plot ek with k = 1, 2, · · · , 7 by using the Matlab function semilogy. Include the
figure in your answer.
Page 2 of 4
Question 4: Integration (10%)
Apply the composite Simpson’s rule on n equally spaced subintervals to approximate
the integral
Z 2
1
dx.
(2)
1 x
4.1) According to the error term for the composite Simpson’s rule, find a condition
on n such that the approximation of the integral (2) has an absolute error less than
10−4 . State your result as an inequality for n and explain how you derived it.
4.2) Use the smallest n, which satisfies the condition obtained in Question 4.1,
in the composite Simpson’s rule to compute the approximation of (2). State your
results on n and the approximated integral value. For this question, you will need
the Matlab function MySimpson.m, which is saved in the same folder as this exam
assignment.
Question 5: LU factorization with pivoting (10%)
Use Matlab to apply LU factorization on the matrix


2 −2 3 −3
1 −1 2 −1

A=
1 −1 4 3 
1 1 1 0
(3)
and obtain P A = L U , where P is a permutation matrix, L is a unit lowertriangular matrix, and U is an upper triangular matrix.
5.1) According to P , do we need pivoting to obtain LU factorization of A given in
(3)? If pivoting is needed, how should we interchange the rows in A?
5.2) Explain the reason for always performing pivoting in LU factorization.
Question 6: Boundary-value problem (20%)
We consider the boundary-value problem
x00 (t) = x0 (t) + x(t) − (2t − 1)et ,
x(1) = 3e,
x(2) = 5e
1<t<2
(4)
2
6.1) Rewrite the problem (4) as a system of first-order differential equations, and
implement a Matlab function to return the right-hand side of the system. Include
the Matlab code in the pdf file with your answers.
6.2) Use the Matlab function ode45 with the default setting to perform two “shootings” for the ordinary differential equation (4) with the initial conditions
x(1) = 3e,
x0 (1) = z = 10
and
x(1) = 3e,
respectively. State the values of x(2) in these two shootings.
Page 3 of 4
x0 (1) = z = 25,
6.3) In the shooting method, we consider the value of x at the end point, i.e., x(2),
as a function ϕ(z) of z and z = x0 (1). Based on the answers in Question 6.2, you
have two points on the graph (z, ϕ(z)). Use one iteration of the secant method on
the equation ϕ(z) = x(2) = 5e2 to calculate a new iterate ẑ. State the value of the
new ẑ, and perform a new shooting for the ordinary differential equation (4) with
the initial condition
x(1) = 3e, x0 (1) = ẑ.
Include a plot of the new shooting (t, x(t)) for t ∈ [1, 2] in your answer.
End.
Page 4 of 4
Download